From a4152172921c8c3ec57c4569fcf6cb1a2d45765b Mon Sep 17 00:00:00 2001 From: Eugene Pimenov Date: Sat, 30 Jan 2010 10:51:31 +0300 Subject: [PATCH] When routing creates a singular resource, it should add itself to name_prefix. --- actionpack/lib/action_dispatch/routing/mapper.rb | 6 +++++- actionpack/test/dispatch/routing_test.rb | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 5199984..f375e9b 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -452,7 +452,11 @@ module ActionDispatch scope(:path => resource.name.to_s, :controller => resource.controller) do with_scope_level(:resource, resource) do - yield if block_given? + if block_given? + scope(:name_prefix => resource.singular, :as => "") do + yield + end + end get :show if resource.actions.include?(:show) post :create if resource.actions.include?(:create) diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index dfe824f..db369ae 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -153,6 +153,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :descriptions root :to => 'projects#index' end + + resource :subscription do + put :renew + resources :cards + end end end @@ -709,6 +714,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_singular_resource_adds_itself_to_name_prefix + with_test_routes do + assert_equal '/subscription/renew', renew_subscription_path + assert_equal '/subscription/cards', subscription_cards_path + end + end + private def with_test_routes real_routes, temp_routes = ActionController::Routing::Routes, Routes -- 1.6.6.rc1.42.gf9ad7.dirty