aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md13
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb3
-rw-r--r--actionpack/test/dispatch/routing/inspector_test.rb4
-rw-r--r--actionpack/test/dispatch/routing/route_set_test.rb2
4 files changed, 20 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 24dc207656..4e67627d8b 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,3 +1,16 @@
+* Add ability to set a prefix name for routes which have hyphen(s).
+
+ get '/contact-us' => 'pages#contact'
+ get '/about-us' => 'pages#about_us'
+
+ The above routes will inspected to
+
+ Prefix Verb URI Pattern Controller#Action
+ contact_us GET /contact-us(.:format) pages#contact
+ about_us GET /about-us(.:format) pages#about_us
+
+ *Amr Tamimi*
+
* Fix stream closing when sending file with `ActionController::Live` included.
Fixes #12381
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 18f37dc732..d724633245 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1440,7 +1440,7 @@ module ActionDispatch
path = path_for_action(action, options.delete(:path))
action = action.to_s.dup
- if action =~ /^[\w\/]+$/
+ if action =~ /^[\w\-\/]+$/
options[:action] ||= action unless action.include?("/")
else
action = nil
@@ -1636,6 +1636,7 @@ module ActionDispatch
when :root
[name_prefix, collection_name, prefix]
else
+ prefix.gsub!(/\-/, '_') if prefix.is_a?(String)
[name_prefix, member_name, prefix]
end
diff --git a/actionpack/test/dispatch/routing/inspector_test.rb b/actionpack/test/dispatch/routing/inspector_test.rb
index 18a52f13a7..2746c683ba 100644
--- a/actionpack/test/dispatch/routing/inspector_test.rb
+++ b/actionpack/test/dispatch/routing/inspector_test.rb
@@ -37,6 +37,7 @@ module ActionDispatch
end
engine.routes.draw do
get '/cart', :to => 'cart#show'
+ get '/view-cart', :to => 'cart#show'
end
output = draw do
@@ -50,7 +51,8 @@ module ActionDispatch
" blog /blog Blog::Engine",
"",
"Routes for Blog::Engine:",
- " cart GET /cart(.:format) cart#show"
+ " cart GET /cart(.:format) cart#show",
+ "view_cart GET /view-cart(.:format) cart#show"
], output
end
diff --git a/actionpack/test/dispatch/routing/route_set_test.rb b/actionpack/test/dispatch/routing/route_set_test.rb
index 0e488d2b88..3831c4c585 100644
--- a/actionpack/test/dispatch/routing/route_set_test.rb
+++ b/actionpack/test/dispatch/routing/route_set_test.rb
@@ -30,10 +30,12 @@ module ActionDispatch
draw do
get 'foo', to: SimpleApp.new('foo#index')
get 'bar', to: SimpleApp.new('bar#index')
+ get 'foo-bar', to: SimpleApp.new('bar#index')
end
assert_equal '/foo', url_helpers.foo_path
assert_equal '/bar', url_helpers.bar_path
+ assert_equal '/foo-bar', url_helpers.foo_bar_path
end
test "url helpers are updated when route is updated" do