aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2013-06-25 11:00:19 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2013-06-25 11:00:19 +0100
commit622e4ab424ea260cd3ebe3768b1a2a4e5ae1384e (patch)
tree9d4ab215a75059ee9d187cef7ed4bd92fb7ffbd4
parentca23e6d4d3e3a14e2e3ec1af46ca2bd2c7d5576c (diff)
downloadrails-622e4ab424ea260cd3ebe3768b1a2a4e5ae1384e.tar.gz
rails-622e4ab424ea260cd3ebe3768b1a2a4e5ae1384e.tar.bz2
rails-622e4ab424ea260cd3ebe3768b1a2a4e5ae1384e.zip
Fix shorthand routes where controller and action are in the scope
Merge `:action` from routing scope and assign endpoint if both `:controller` and `:action` are present. The endpoint assignment only occurs if there is no `:to` present in the options hash so should only affect routes using the shorthand syntax (i.e. endpoint is inferred from the the path). Fixes #9856 Backport of 37b4276
-rw-r--r--actionpack/CHANGELOG.md9
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb8
-rw-r--r--actionpack/test/dispatch/routing_test.rb13
3 files changed, 30 insertions, 0 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 5508fb9453..ac260a9592 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,5 +1,14 @@
## unreleased ##
+* Merge `:action` from routing scope and assign endpoint if both `:controller`
+ and `:action` are present. The endpoint assignment only occurs if there is
+ no `:to` present in the options hash so should only affect routes using the
+ shorthand syntax (i.e. endpoint is inferred from the the path).
+
+ Fixes #9856
+
+ *Yves Senn*, *Andrew White*
+
* Always escape the result of `link_to_unless` method.
Before:
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index d71b21efc3..bfa816798d 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -779,6 +779,10 @@ module ActionDispatch
child
end
+ def merge_action_scope(parent, child) #:nodoc:
+ child
+ end
+
def merge_path_names_scope(parent, child) #:nodoc:
merge_options_scope(parent, child)
end
@@ -1253,6 +1257,10 @@ module ActionDispatch
paths = [path] + rest
end
+ if @scope[:controller] && @scope[:action]
+ options[:to] ||= "#{@scope[:controller]}##{@scope[:action]}"
+ end
+
path_without_format = path.to_s.sub(/\(\.:format\)$/, '')
if using_match_shorthand?(path_without_format, options)
options[:to] ||= path_without_format.gsub(%r{^/}, "").sub(%r{/([^/]*)$}, '#\1')
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 88a5c37c43..c5a5c07b80 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -529,6 +529,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
end
+
+ scope '/job', controller: 'job' do
+ scope ':id', action: 'manage_applicant' do
+ get "/active"
+ end
+ end
end
end
@@ -1444,6 +1450,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
+ def test_controller_option_with_nesting_and_leading_slash
+ with_test_routes do
+ get '/job/5/active'
+ assert_equal 'job#manage_applicant', @response.body
+ end
+ end
+
def test_dynamically_generated_helpers_on_collection_do_not_clobber_resources_url_helper
with_test_routes do
assert_equal '/replies', replies_path