This project is archived and is in readonly mode.

#5191 ✓stale
gucki

resource/resources inside namespace generates wrong routes

Reported by gucki | July 25th, 2010 @ 12:34 PM

Using latest rails3 edge and the following routes.rb:

Rails.application.routes.draw do |map|
  namespace(:my) do
    resource :text
  end

  map.namespace(:a) do |a|
    a.resource :text
  end
end

Output:

         POST   /my/text(.:format)      {:controller=>"my/texts", :action=>"create"}

new_my_text GET /my/text/new(.:format) {:controller=>"my/texts", :action=>"new"}

         GET    /my/text(.:format)      {:controller=>"my/texts", :action=>"show"}
         PUT    /my/text(.:format)      {:controller=>"my/texts", :action=>"update"}
 my_text DELETE /my/text(.:format)      {:controller=>"my/texts", :action=>"destroy"}

edit_my_text GET /my/text/edit(.:format) {:controller=>"my/texts", :action=>"edit"}

new_a_text GET /a/text/new(.:format) {:controller=>"a/texts", :action=>"new"} edit_a_text GET /a/text/edit(.:format) {:controller=>"a/texts", :action=>"edit"}

  a_text GET    /a/text(.:format)       {:controller=>"a/texts", :action=>"show"}
         PUT    /a/text(.:format)       {:controller=>"a/texts", :action=>"update"}
         DELETE /a/text(.:format)       {:controller=>"a/texts", :action=>"destroy"}
         POST   /a/text(.:format)       {:controller=>"a/texts", :action=>"create"}

As you can see the "my_text" path is on the DELETE method, while the "a_text" path is on the GET method (which is correct!).

Comments and changes to this ticket

  • gucki

    gucki July 25th, 2010 @ 12:36 PM

    • Tag changed from regression, router to rails3 routes, regression, router

    Nicer display of thew generated routes:

                 GET    /my/text(.:format)      {:action=>"show", :controller=>"my/texts"}
                 POST   /my/text(.:format)      {:action=>"create", :controller=>"my/texts"}
                 PUT    /my/text(.:format)      {:action=>"update", :controller=>"my/texts"}
         my_text DELETE /my/text(.:format)      {:action=>"destroy", :controller=>"my/texts"}
     new_my_text GET    /my/text/new(.:format)  {:action=>"new", :controller=>"my/texts"}
    edit_my_text GET    /my/text/edit(.:format) {:action=>"edit", :controller=>"my/texts"}
    
      new_a_text GET    /a/text/new(.:format)   {:controller=>"a/texts", :action=>"new"}
     edit_a_text GET    /a/text/edit(.:format)  {:controller=>"a/texts", :action=>"edit"}
          a_text GET    /a/text(.:format)       {:controller=>"a/texts", :action=>"show"}
                 PUT    /a/text(.:format)       {:controller=>"a/texts", :action=>"update"}
                 DELETE /a/text(.:format)       {:controller=>"a/texts", :action=>"destroy"}
                 POST   /a/text(.:format)       {:controller=>"a/texts", :action=>"create"}
    
  • gucki

    gucki July 25th, 2010 @ 12:39 PM

    And just for completeness, the same bug is present with resourceS inside namespace:

                 GET    /my/texts(.:format)          {:controller=>"my/texts", :action=>"index"}
        my_texts POST   /my/texts(.:format)          {:controller=>"my/texts", :action=>"create"}
     new_my_text GET    /my/texts/new(.:format)      {:controller=>"my/texts", :action=>"new"}
                 GET    /my/texts/:id(.:format)      {:controller=>"my/texts", :action=>"show"}
                 PUT    /my/texts/:id(.:format)      {:controller=>"my/texts", :action=>"update"}
         my_text DELETE /my/texts/:id(.:format)      {:controller=>"my/texts", :action=>"destroy"}
    edit_my_text GET    /my/texts/:id/edit(.:format) {:controller=>"my/texts", :action=>"edit"}
    
         a_texts GET    /a/texts(.:format)           {:controller=>"a/texts", :action=>"index"}
                 POST   /a/texts(.:format)           {:controller=>"a/texts", :action=>"create"}
      new_a_text GET    /a/texts/new(.:format)       {:controller=>"a/texts", :action=>"new"}
     edit_a_text GET    /a/texts/:id/edit(.:format)  {:controller=>"a/texts", :action=>"edit"}
          a_text GET    /a/texts/:id(.:format)       {:controller=>"a/texts", :action=>"show"}
                 PUT    /a/texts/:id(.:format)       {:controller=>"a/texts", :action=>"update"}
                 DELETE /a/texts/:id(.:format)       {:controller=>"a/texts", :action=>"destroy"}
    
  • gucki

    gucki July 25th, 2010 @ 12:48 PM

    Ok, the bug seems to happen even without namespace:

    Test::Application.routes.draw do |map|
      resources :as
      map.resources :bs
    end
    
           GET    /as(.:format)          {:controller=>"as", :action=>"index"}
        as POST   /as(.:format)          {:controller=>"as", :action=>"create"}
     new_a GET    /as/new(.:format)      {:controller=>"as", :action=>"new"}
           GET    /as/:id(.:format)      {:controller=>"as", :action=>"show"}
           PUT    /as/:id(.:format)      {:controller=>"as", :action=>"update"}
         a DELETE /as/:id(.:format)      {:controller=>"as", :action=>"destroy"}
    edit_a GET    /as/:id/edit(.:format) {:controller=>"as", :action=>"edit"}
    
        bs GET    /bs(.:format)          {:controller=>"bs", :action=>"index"}
           POST   /bs(.:format)          {:controller=>"bs", :action=>"create"}
     new_b GET    /bs/new(.:format)      {:controller=>"bs", :action=>"new"}
    edit_b GET    /bs/:id/edit(.:format) {:controller=>"bs", :action=>"edit"}
         b GET    /bs/:id(.:format)      {:controller=>"bs", :action=>"show"}
           PUT    /bs/:id(.:format)      {:controller=>"bs", :action=>"update"}
           DELETE /bs/:id(.:format)      {:controller=>"bs", :action=>"destroy"}
    
  • gucki

    gucki July 25th, 2010 @ 01:24 PM

    • Tag changed from rails3 routes, regression, router to rails3 routes, patch, regression, router

    The attached patch seems to fix the bugs for me. Please review :-)

  • gucki

    gucki July 25th, 2010 @ 01:26 PM

    Hm, lighthouse seems to have some troubles with the attached file. Here it is again.

  • gucki

    gucki July 25th, 2010 @ 01:31 PM

    As the attachment is still not loading, here as a pastie: http://pastie.org/1059180

  • Rohit Arondekar

    Rohit Arondekar October 15th, 2010 @ 11:05 AM

    • Importance changed from “” to “Low”

    Any updates here? Is this still an issue?

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:30 PM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:30 PM

    • State changed from “open” to “stale”

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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages