From 4f57cd5d39c92c4d53b979210ce34a910ed32c3a Mon Sep 17 00:00:00 2001 From: Mutwin Kraus Date: Wed, 18 Nov 2009 21:34:29 +0100 Subject: [PATCH] Fix resources routing to new action The router used to route to show with id "new" instead of the new action when more than one resource is defined. By changing the order of the created routes this was fixed. --- actionpack/lib/action_dispatch/routing/mapper.rb | 12 ++++++------ actionpack/test/dispatch/routing_test.rb | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 7d770de..1d891e2 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -67,18 +67,18 @@ module ActionDispatch with_scope_level(:resources) do yield if block_given? + collection do + get "", :to => :index, :as => "#{plural}" + post "", :to => :create + get "new", :to => :new, :as => "new_#{singular}" + end + member do get "", :to => :show, :as => "#{singular}" put "", :to => :update delete "", :to => :destroy get "edit", :to => :edit, :as => "edit_#{singular}" end - - collection do - get "", :to => :index, :as => "#{plural}" - post "", :to => :create - get "new", :to => :new, :as => "new_#{singular}" - end end end end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index ca07bc7..efec2d5 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -41,6 +41,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get 'admin/accounts', :to => "queenbee#accounts" end + resources :resources + resources :projects, :controller => :project do resources :involvements, :attachments @@ -188,6 +190,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_failing_projects_test + with_test_routes do + new_project_path + end + end + def test_projects with_test_routes do get '/projects' -- 1.6.4.1