This project is archived and is in readonly mode.

#1400 ✓resolved
Geoff Garside

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

Reported by Geoff Garside | November 18th, 2008 @ 02:45 PM | in 2.x

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

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

Comments and changes to this ticket

  • Geoff Garside

    Geoff Garside November 18th, 2008 @ 03:17 PM

    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.

  • Geoff Garside
  • Geoff Garside

    Geoff Garside November 24th, 2008 @ 12:31 PM

    • 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
          assert_equal :get, set.named_routes.routes[:product].conditions[:method]
  • Michael Koziarski

    Michael Koziarski November 24th, 2008 @ 06:22 PM

    • State changed from “new” to “resolved”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket