Allowing :nested option to accept an array for deep nesting
This commit is contained in:
@@ -41,6 +41,10 @@ module CanCan
|
||||
#
|
||||
# load_resource :nested => :author
|
||||
#
|
||||
# Deep nesting can be defined in an array.
|
||||
#
|
||||
# load_resource :nested => [:publisher, :author]
|
||||
#
|
||||
# [:+collection+]
|
||||
# Specify which actions are resource collection actions in addition to :+index+. This
|
||||
# is usually not necessary because it will try to guess depending on if an :+id+
|
||||
|
||||
@@ -34,11 +34,12 @@ module CanCan
|
||||
end
|
||||
|
||||
def parent_resource
|
||||
if @options[:nested]
|
||||
parent = ControllerResource.new(@controller, @options[:nested])
|
||||
parent.find(@params["#{@options[:nested]}_id".to_sym])
|
||||
parent
|
||||
parent = nil
|
||||
[@options[:nested]].flatten.compact.each do |name|
|
||||
parent = ControllerResource.new(@controller, name, parent)
|
||||
parent.find(@params["#{name}_id".to_sym])
|
||||
end
|
||||
parent
|
||||
end
|
||||
|
||||
def model_name
|
||||
|
||||
Reference in New Issue
Block a user