diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2012-07-20 09:59:37 +0100 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2012-07-20 10:50:11 +0100 |
commit | 27619e34d42183f24c80648ee7a46b7fee348327 (patch) | |
tree | 1570a3c6764bec1703e24b7ee801b485f0d21cd5 /actionpack/lib/action_dispatch | |
parent | 3b3ca133071419a42c0b1f55c96fc604ff73f2ac (diff) | |
download | rails-27619e34d42183f24c80648ee7a46b7fee348327.tar.gz rails-27619e34d42183f24c80648ee7a46b7fee348327.tar.bz2 rails-27619e34d42183f24c80648ee7a46b7fee348327.zip |
Support constraints on resource custom params when nesting
The Mapper looks for a :id constraint in the scope to see whether it
should apply a constraint for nested resources. Since #5581 added support
for resource params other than :id, we need to check for a constraint on
the parent resource's param name and not assume it's :id.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index ee90bfe63f..7f8257a063 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -917,7 +917,7 @@ module ActionDispatch @path = (options[:path] || @name).to_s @controller = (options[:controller] || @name).to_s @as = options[:as] - @param = options[:param] || :id + @param = (options[:param] || :id).to_sym @options = options end @@ -969,8 +969,12 @@ module ActionDispatch "#{path}/#{new_path}" end + def nested_param + :"#{singular}_#{param}" + end + def nested_scope - "#{path}/:#{singular}_#{param}" + "#{path}/:#{nested_param}" end end @@ -1481,18 +1485,18 @@ module ActionDispatch def nested_options #:nodoc: options = { :as => parent_resource.member_name } options[:constraints] = { - :"#{parent_resource.singular}_id" => id_constraint - } if id_constraint? + parent_resource.nested_param => param_constraint + } if param_constraint? options end - def id_constraint? #:nodoc: - @scope[:constraints] && @scope[:constraints][:id].is_a?(Regexp) + def param_constraint? #:nodoc: + @scope[:constraints] && @scope[:constraints][parent_resource.param].is_a?(Regexp) end - def id_constraint #:nodoc: - @scope[:constraints][:id] + def param_constraint #:nodoc: + @scope[:constraints][parent_resource.param] end def canonical_action?(action, flag) #:nodoc: |