aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/mapper.rb
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2014-04-11 10:20:54 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2014-04-11 10:20:54 +0100
commite10f26f9e90f2fe6c4cd18f70c1e559f2250da56 (patch)
tree83f9b424b8ae02a25b660b5ddbc954cab71d4ae6 /actionpack/lib/action_dispatch/routing/mapper.rb
parent77252c332e28dbc385a2e7865905bf3442972cf3 (diff)
downloadrails-e10f26f9e90f2fe6c4cd18f70c1e559f2250da56.tar.gz
rails-e10f26f9e90f2fe6c4cd18f70c1e559f2250da56.tar.bz2
rails-e10f26f9e90f2fe6c4cd18f70c1e559f2250da56.zip
Only make deeply nested routes shallow when parent is shallow
Since `:shallow` may be set at any point in the resource nesting we should only make the new and collection routes shallow when the parent is shallow. This is a bit of a hack but until the mapper is refactored to an object graph instead of a hash of merged values it's the best we can do. Fixes #14684.
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 6f0b49cf28..77718a14c1 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -995,6 +995,7 @@ module ActionDispatch
@as = options[:as]
@param = (options[:param] || :id).to_sym
@options = options
+ @shallow = false
end
def default_actions
@@ -1055,6 +1056,13 @@ module ActionDispatch
"#{path}/:#{nested_param}"
end
+ def shallow=(value)
+ @shallow = value
+ end
+
+ def shallow?
+ @shallow
+ end
end
class SingletonResource < Resource #:nodoc:
@@ -1361,7 +1369,7 @@ module ActionDispatch
end
with_scope_level(:nested) do
- if shallow? && nesting_depth > 1
+ if shallow? && shallow_nesting_depth > 1
shallow_scope(parent_resource.nested_scope, nested_options) { yield }
else
scope(parent_resource.nested_scope, nested_options) { yield }
@@ -1576,6 +1584,7 @@ module ActionDispatch
end
def resource_scope(kind, resource) #:nodoc:
+ resource.shallow = @scope[:shallow]
old_resource, @scope[:scope_level_resource] = @scope[:scope_level_resource], resource
@nesting.push(resource)
@@ -1600,6 +1609,10 @@ module ActionDispatch
@nesting.size
end
+ def shallow_nesting_depth #:nodoc:
+ @nesting.select(&:shallow?).size
+ end
+
def param_constraint? #:nodoc:
@scope[:constraints] && @scope[:constraints][parent_resource.param].is_a?(Regexp)
end