Permalink
Browse files

Prevent clashing named routes when using uncountable resources. Closes

…#9598

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7526 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent eede82c commit 045aee89126f87b0519518c9735fe050cb907f23 @NZKoz NZKoz committed Sep 21, 2007
Showing with 12 additions and 2 deletions.
  1. +12 −2 actionpack/lib/action_controller/resources.rb
@@ -98,6 +98,10 @@ def action_separator
@action_separator ||= Base.resource_action_separator
end
+ def uncountable?
+ @singular.to_s == @plural.to_s
+ end
+
protected
def arrange_actions
@collection_methods = arrange_actions_by_methods(options.delete(:collection))
@@ -441,8 +445,14 @@ def map_collection_actions(map, resource)
def map_default_collection_actions(map, resource)
index_action_options = action_options_for("index", resource)
- map.named_route("#{resource.name_prefix}#{resource.plural}", resource.path, index_action_options)
- map.named_route("formatted_#{resource.name_prefix}#{resource.plural}", "#{resource.path}.:format", index_action_options)
+ index_route_name = "#{resource.name_prefix}#{resource.plural}"
+
+ if resource.uncountable?
+ index_route_name << "_index"
+ end
+
+ map.named_route(index_route_name, resource.path, index_action_options)
+ map.named_route("formatted_#{index_route_name}", "#{resource.path}.:format", index_action_options)
create_action_options = action_options_for("create", resource)
map.connect(resource.path, create_action_options)

0 comments on commit 045aee8

Please sign in to comment.