Permalink
Browse files

Transform dashes to underscores in resource route names

Fixes #13824
  • Loading branch information...
1 parent 94ce514 commit 345555cd4cfd6fad68752292e5780387672e167e @bronzle bronzle committed with pixeltrix Jan 24, 2014
View
8 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1442,7 +1442,7 @@ def add_route(action, options) # :nodoc:
action = action.to_s.dup
if action =~ /^[\w\-\/]+$/
- options[:action] ||= action unless action.include?("/")
+ options[:action] ||= action.tr('-', '_') unless action.include?("/")
else
action = nil
end
@@ -1607,10 +1607,11 @@ def action_path(name, path = nil) #:nodoc:
def prefix_name_for_action(as, action) #:nodoc:
if as
- as.to_s
+ prefix = as
elsif !canonical_action?(action, @scope[:scope_level])
- action.to_s
+ prefix = action
end
+ prefix.to_s.tr('-', '_') if prefix
end
def name_for_action(as, action) #:nodoc:
@@ -1637,7 +1638,6 @@ def name_for_action(as, action) #:nodoc:
when :root
[name_prefix, collection_name, prefix]
else
- prefix.gsub!(/\-/, '_') if prefix.is_a?(String)
[name_prefix, member_name, prefix]
end
View
16 actionpack/test/dispatch/routing/inspector_test.rb
@@ -185,12 +185,22 @@ def test_rake_routes_shows_routes_with_dashes
output = draw do
get 'about-us' => 'pages#about_us'
get 'our-work/latest'
+
+ resources :photos, only: [:show] do
+ get 'user-favorites', on: :collection
+ get 'preview-photo', on: :member
+ get 'summary-text'
+ end
end
assert_equal [
- " Prefix Verb URI Pattern Controller#Action",
- " about_us GET /about-us(.:format) pages#about_us",
- "our_work_latest GET /our-work/latest(.:format) our_work#latest"
+ " Prefix Verb URI Pattern Controller#Action",
+ " about_us GET /about-us(.:format) pages#about_us",
+ " our_work_latest GET /our-work/latest(.:format) our_work#latest",
+ "user_favorites_photos GET /photos/user-favorites(.:format) photos#user_favorites",
+ " preview_photo_photo GET /photos/:id/preview-photo(.:format) photos#preview_photo",
+ " photo_summary_text GET /photos/:photo_id/summary-text(.:format) photos#summary_text",
+ " photo GET /photos/:id(.:format) photos#show"
], output
end

0 comments on commit 345555c

Please sign in to comment.