From 521ef3c40f34d61d42d092eb39348a1be52ac57d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 13 Jan 2010 11:45:27 -0600 Subject: Passing in a crud action overloads the default action instead of creating a new member action. --- actionpack/lib/action_dispatch/routing/mapper.rb | 11 +++++++++-- actionpack/test/dispatch/routing_test.rb | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index f7fb4ddd7a..e283cf0403 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -321,6 +321,8 @@ module ActionDispatch end module Resources + CRUD_ACTIONS = [:index, :show, :new, :edit, :create, :update, :destroy] + class Resource #:nodoc: attr_reader :plural, :singular @@ -489,8 +491,13 @@ module ActionDispatch end if args.first.is_a?(Symbol) - with_exclusive_name_prefix(args.first) do - return match("/#{args.first}(.:format)", options.merge(:to => args.first.to_sym)) + action = args.first + if CRUD_ACTIONS.include?(action) + return match("(.:format)", options.merge(:to => action)) + else + with_exclusive_name_prefix(action) do + return match("/#{action}(.:format)", options.merge(:to => action)) + end end end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index bcd6a5278c..61cd2e3007 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -22,6 +22,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest delete 'logout' => :destroy, :as => :logout end + resource :session do + get :create + end + match 'account/logout' => redirect("/logout"), :as => :logout_redirect match 'account/login', :to => redirect("/login") @@ -170,6 +174,19 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_session_singleton_resource + with_test_routes do + get '/session' + assert_equal 'sessions#create', @response.body + + post '/session' + assert_equal 'sessions#create', @response.body + + get '/session/new' + assert_equal 'sessions#new', @response.body + end + end + def test_redirect_modulo with_test_routes do get '/account/modulo/name' -- cgit v1.2.3