Skip to content

Instantly share code, notes, and snippets.

@javierv
Created August 5, 2010 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javierv/510293 to your computer and use it in GitHub Desktop.
Save javierv/510293 to your computer and use it in GitHub Desktop.
Named routes for irregular plural of the plural
From 89ddcbe36e627919f0da45e414b65c5833643d48 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Javier=20Mart=C3=ADn?= <elretirao@elretirao.net>
Date: Thu, 5 Aug 2010 21:59:35 +0200
Subject: [PATCH] Generated collection named routes now work with irregular plural of the plural.
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".
---
actionpack/lib/action_dispatch/routing/mapper.rb | 2 +-
actionpack/test/dispatch/routing_test.rb | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 526c97f..7af3e83 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -508,7 +508,7 @@ module ActionDispatch
# Checks for uncountable plurals, and appends "_index" if they're.
def collection_name
- singular == plural ? "#{plural}_index" : plural
+ singular == name ? "#{name}_index" : name
end
def resource_scope
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 4808663..6d5d4f0 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -187,6 +187,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
resources :sheep
+ resources :taxis
resources :clients do
namespace :google do
@@ -977,6 +978,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
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
get '/pt/projetos'
--
1.7.0.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment