From fb2b14e5573683bb69a32c7c9cb7544c51387576 Mon Sep 17 00:00:00 2001 From: Jan De Poorter Date: Thu, 25 Feb 2010 16:21:41 +0100 Subject: [PATCH] Add _index to named collection routes for uncountable resources (e.g. Sheep) --- actionpack/lib/action_dispatch/routing/mapper.rb | 6 +++++- actionpack/test/dispatch/routing_test.rb | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index bead321..200fd45 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -397,7 +397,11 @@ module ActionDispatch end def collection_name - plural + uncountable? ? "#{plural}_index" : plural + end + + def uncountable? + singular == plural end def name_for_action(action) diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index e29127f..dccd8ef 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -107,6 +107,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :posts, :only => [:index, :show] do resources :comments, :except => :destroy end + + resources :sheep match 'sprockets.js' => ::TestRoutingMapper::SprocketsApp @@ -493,6 +495,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_raise(ActionController::RoutingError) { delete '/posts/1/comments' } end end + + def test_resources_for_uncountable_names + with_test_routes do + assert_equal '/sheep', sheep_index_path + assert_equal '/sheep/1', sheep_path(1) + end + end def test_path_names with_test_routes do -- 1.6.5.7