From 41f3ccd2ca73f0029147ae613b7d5e16c5da1874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Mart=C3=ADn?= Date: Sat, 14 Aug 2010 19:06:48 +0200 Subject: [PATCH] Don't pluralize collection named routes twice. 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. --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- actionpack/test/dispatch/routing_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index c118c72440199..93ed6a8737989 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -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 diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 3f090b72540ba..55235b6e9e2f5 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -188,6 +188,7 @@ def self.matches?(request) end resources :sheep + resources :taxis resources :clients do namespace :google do @@ -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