Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] map.resource should generate default route with :get not :post

#1400

I've just noticed a strange issue with map.resource which I can't seem to replicate with tests but this is what I'm seeing

I've got a simple config/routes.rb


ActionController::Routing::Routes.draw do |map|
  map.resource :dashboard
end

and this is the output from rake routes


               dashboard POST   /dashboard              {:controller=>"dashboards", :action=>"create"}
     formatted_dashboard POST   /dashboard.:format      {:controller=>"dashboards", :action=>"create"}
           new_dashboard GET    /dashboard/new          {:controller=>"dashboards", :action=>"new"}
 formatted_new_dashboard GET    /dashboard/new.:format  {:controller=>"dashboards", :action=>"new"}
          edit_dashboard GET    /dashboard/edit         {:controller=>"dashboards", :action=>"edit"}
formatted_edit_dashboard GET    /dashboard/edit.:format {:controller=>"dashboards", :action=>"edit"}
                         GET    /dashboard              {:controller=>"dashboards", :action=>"show"}
                         GET    /dashboard.:format      {:controller=>"dashboards", :action=>"show"}
                         PUT    /dashboard              {:controller=>"dashboards", :action=>"update"}
                         PUT    /dashboard.:format      {:controller=>"dashboards", :action=>"update"}
                         DELETE /dashboard              {:controller=>"dashboards", :action=>"destroy"}
                         DELETE /dashboard.:format      {:controller=>"dashboards", :action=>"destroy"}

notice how the default :dashboard route is defined for the :create action and not the :show action as you would expect. As I said I've tried to replicate this in actionpack/test/controller/resources_test.rb but I can't seem to figure out how to exercise the routes in the right way.

This is using a new edge application created with rev 45ba4ec626b79dda8534f13b3eb01524e0734781

Reported by Geoff Garside · November 18th, 2008 @ 02:45 PM

State: resolved
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Geoff Garside
    Geoff Garside

    The attached patch seems to fix this from visual inspection but I still can't replicate the issue in tests.

    The patch just changes the order in which the routes for a map.resource are added to the route set, this has the effect that :show gets the dashboard named route and not :create.

    November 18th, 2008 @ 03:17 PM

  2. Geoff Garside
  3. Geoff Garside
    Geoff Garside
    • Tag changed from actioncontroller, actionpack, edge, resource, routes, routing to actioncontroller, actionpack, edge, patch, resource, routes, routing
    • Title changed from map.resource generating default named route to :create to [PATCH] map.resource should generate default route with :get not :post

    Added a test case, aside from that the patch remains the same. The test is as below

    
    # actionpack/test/controller/resources_test.rb
      def test_default_singleton_restful_route_uses_get
        with_routing do |set|
          set.draw do |map|
            map.resource :product
          end
    
          assert_equal :get, set.named_routes.routes[:product].conditions[:method]
        end
      end
    

    November 24th, 2008 @ 12:31 PM

  4. Michael Koziarski
    Michael Koziarski
    • State changed from new to resolved

    November 24th, 2008 @ 06:22 PM