Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Automatically convert dashes to underscores in shorthand routes

  • Loading branch information...
commit f9f32e04ad57c37353a756673794a41026f65a34 1 parent 746abbc
@mellowi mellowi authored pixeltrix committed
View
1  actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1410,6 +1410,7 @@ def match(path, *rest)
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)
View
10 actionpack/test/dispatch/routing_test.rb
@@ -2912,6 +2912,16 @@ def test_trailing_slash
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)
Please sign in to comment.
Something went wrong with that request. Please try again.