aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorMikko Johansson <mikko.johansson@gmail.com>2014-01-20 17:31:11 +0200
committerAndrew White <andyw@pixeltrix.co.uk>2014-01-20 15:37:23 +0000
commitf9f32e04ad57c37353a756673794a41026f65a34 (patch)
tree3988ecb169ab0f9dc1c5c9c159ceeff701b02b88 /actionpack
parent746abbcc31f795eaa8e31d7b3a94d63cc4d5c581 (diff)
downloadrails-f9f32e04ad57c37353a756673794a41026f65a34.tar.gz
rails-f9f32e04ad57c37353a756673794a41026f65a34.tar.bz2
rails-f9f32e04ad57c37353a756673794a41026f65a34.zip
Automatically convert dashes to underscores in shorthand routes
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb1
-rw-r--r--actionpack/test/dispatch/routing_test.rb10
2 files changed, 11 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index d724633245..6a4d7c3afa 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1410,6 +1410,7 @@ module ActionDispatch
path_without_format = _path.to_s.sub(/\(\.:format\)$/, '')
if using_match_shorthand?(path_without_format, route_options)
route_options[:to] ||= path_without_format.gsub(%r{^/}, "").sub(%r{/([^/]*)$}, '#\1')
+ route_options[:to].tr!("-", "_")
end
decomposed_match(_path, route_options)
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 795911497e..497c3e568c 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -2912,6 +2912,16 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
assert @response.ok?, 'route with trailing slash and with QUERY_STRING should work'
end
+ def test_shorthand_route_with_dashes_in_path
+ draw do
+ get '/about-us/index'
+ end
+
+ get '/about-us/index'
+ assert_equal 'about_us#index', @response.body
+ assert_equal '/about-us/index', about_us_index_path
+ end
+
private
def draw(&block)