Skip to content

Commit

Permalink
Don't pluralize collection named routes twice.
Browse files Browse the repository at this point in the history
In english, usually pluralizing a word twice gives the same result as pluralizing it just once.

However, with some words, and in many foreign languages, this is not the case.

For example, the plural of "taxi" is "taxis", but the plural of "taxis" is "taxes". We were pluralizing the resource :taxis, so were generating "taxes_path" instead of "taxis_path".

It affected applications using custom inflection rules, such as spanish ones.
  • Loading branch information
Javier Martín committed Aug 14, 2010
1 parent b7e7e56 commit 41f3ccd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -511,7 +511,7 @@ def member_name

# Checks for uncountable plurals, and appends "_index" if they're.
def collection_name
singular == plural ? "#{plural}_index" : plural
singular == plural ? "#{name}_index" : name
end

def resource_scope
Expand Down
9 changes: 9 additions & 0 deletions actionpack/test/dispatch/routing_test.rb
Expand Up @@ -188,6 +188,7 @@ def self.matches?(request)
end

resources :sheep
resources :taxis

resources :clients do
namespace :google do
Expand Down Expand Up @@ -965,6 +966,14 @@ def test_resources_for_uncountable_names
assert_equal '/sheep/1/edit', edit_sheep_path(1)
end
end

def test_named_paths_for_resources_with_irregular_plural_of_the_plural
with_test_routes do
assert_equal '/taxis/1', taxi_path(1)
assert_equal '/taxis', taxis_path
assert_raise(NameError) { taxes_path }
end
end

def test_path_names
with_test_routes do
Expand Down

0 comments on commit 41f3ccd

Please sign in to comment.