@@ -137,9 +137,9 @@ def filter_access_filter # :nodoc:
137
137
end
138
138
end
139
139
140
- def load_controller_object ( context_without_namespace = nil ) # :nodoc:
140
+ def load_controller_object ( context_without_namespace = nil , model = nil ) # :nodoc:
141
141
instance_var = :"@#{ context_without_namespace . to_s . singularize } "
142
- model = context_without_namespace . to_s . classify . constantize
142
+ model = model ? model . classify . constantize : context_without_namespace . to_s . classify . constantize
143
143
instance_variable_set ( instance_var , model . find ( params [ :id ] ) )
144
144
end
145
145
@@ -158,10 +158,14 @@ def new_controller_object_from_params (context_without_namespace, parent_context
158
158
model_or_proxy . new ( params [ context_without_namespace . to_s . singularize ] ) )
159
159
end
160
160
161
- def new_blank_controller_object ( context_without_namespace , parent_context_without_namespace , strong_params ) # :nodoc:
162
- model_or_proxy = parent_context_without_namespace ?
163
- instance_variable_get ( :"@#{ parent_context_without_namespace . to_s . singularize } " ) . send ( context_without_namespace . to_sym ) :
164
- context_without_namespace . to_s . classify . constantize
161
+ def new_blank_controller_object ( context_without_namespace , parent_context_without_namespace , strong_params , model ) # :nodoc:
162
+ if model
163
+ model_or_proxy = model . to_s . classify . constantize
164
+ else
165
+ model_or_proxy = parent_context_without_namespace ?
166
+ instance_variable_get ( :"@#{ parent_context_without_namespace . to_s . singularize } " ) . send ( context_without_namespace . to_sym ) :
167
+ context_without_namespace . to_s . classify . constantize
168
+ end
165
169
instance_var = :"@#{ context_without_namespace . to_s . singularize } "
166
170
instance_variable_set ( instance_var ,
167
171
model_or_proxy . new ( ) )
@@ -489,6 +493,7 @@ def filter_resource_access(options = {})
489
493
#:load_method => nil, # only symbol method name
490
494
:no_attribute_check => nil ,
491
495
:context => nil ,
496
+ :model => nil ,
492
497
:nested_in => nil ,
493
498
:strong_parameters => nil
494
499
} . merge ( options )
@@ -548,7 +553,7 @@ def filter_resource_access(options = {})
548
553
controller . send ( new_object_method )
549
554
else
550
555
controller . send ( :new_blank_controller_object ,
551
- options [ :context ] || controller_name , options [ :nested_in ] , options [ :strong_parameters ] )
556
+ options [ :context ] || controller_name , options [ :nested_in ] , options [ :strong_parameters ] , options [ :model ] )
552
557
end
553
558
end
554
559
end
@@ -559,17 +564,18 @@ def filter_resource_access(options = {})
559
564
if controller . respond_to? ( load_method , true )
560
565
controller . send ( load_method )
561
566
else
562
- controller . send ( :load_controller_object , options [ :context ] || controller_name )
567
+ controller . send ( :load_controller_object , options [ :context ] || controller_name , options [ :model ] )
563
568
end
564
569
end
565
- filter_access_to :all , :attribute_check => true , :context => options [ :context ]
570
+ filter_access_to :all , :attribute_check => true , :context => options [ :context ] , :model => options [ :model ]
566
571
567
572
members . merge ( new_actions ) . merge ( collections ) . each do |action , privilege |
568
573
if action != privilege or ( options [ :no_attribute_check ] and options [ :no_attribute_check ] . include? ( action ) )
569
574
filter_options = {
570
575
:strong_parameters => options [ :strong_parameters ] ,
571
576
:context => options [ :context ] ,
572
- :attribute_check => !options [ :no_attribute_check ] || !options [ :no_attribute_check ] . include? ( action )
577
+ :attribute_check => !options [ :no_attribute_check ] || !options [ :no_attribute_check ] . include? ( action ) ,
578
+ :model => options [ :model ]
573
579
}
574
580
filter_options [ :require ] = privilege if action != privilege
575
581
filter_access_to ( action , filter_options )
@@ -675,7 +681,8 @@ def load_object(contr)
675
681
else
676
682
load_object_model = @load_object_model ||
677
683
( @context ? @context . to_s . classify . constantize : contr . class . controller_name . classify . constantize )
678
- instance_var = "@#{ load_object_model . name . underscore } "
684
+ load_object_model = load_object_model . classify . constantize if load_object_model . is_a? ( String )
685
+ instance_var = "@#{ load_object_model . name . demodulize . underscore } "
679
686
object = contr . instance_variable_get ( instance_var )
680
687
unless object
681
688
begin
0 commit comments