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.

Namespaced routes not working on Rails 3

#3673

If my routes.rb contains:

  namespace :admin do
    resources :pages
  end

Then my routes will have the wrong controller ('pages' instead of 'admin/pages').
Output of 'rake routes':


    admin_pages GET    /admin/pages(.:format)          {:controller=>"pages", :action=>"index"}
                POST   /admin/pages(.:format)          {:controller=>"pages", :action=>"create"}
 new_admin_page GET    /admin/pages/new(.:format)      {:controller=>"pages", :action=>"new"}
     admin_page GET    /admin/pages/:id(.:format)      {:controller=>"pages", :action=>"show"}
                PUT    /admin/pages/:id(.:format)      {:controller=>"pages", :action=>"update"}
                DELETE /admin/pages/:id(.:format)      {:controller=>"pages", :action=>"destroy"}
edit_admin_page GET    /admin/pages/:id/edit(.:format) {:controller=>"pages", :action=>"edit"}

My patch seems to fix the issue. As far as I can tell it doesn't break anything.

Reported by Joao Carlos · January 9th, 2010 @ 02:27 AM

State: hold
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Joao Carlos
    Joao Carlos
    • Tag changed from patch routes namespace to namespace, patch, routes

    January 9th, 2010 @ 02:32 AM

  2. José Valim
    José Valim
    • Assigned user set to José Valim

    January 9th, 2010 @ 05:59 PM

  3. Repository
  4. José Valim
    José Valim
    • State changed from new to committed

    Thanks for the patch!

    January 10th, 2010 @ 07:22 PM

  5. Daniele Orlandi
    Daniele Orlandi

    I think the patch should consider the case when we want to explicitly indicate a controller outside the namespace, for example:

    namespace :core
    resource :log end

    namespace :service1 do
    resource :users do

    resource :log, :controller => '/core/log'
    

    end end

    With the patch the 'log' nested route becomes:

    :controller=>"service1//log"}

    May I ask you to reopen this bug and change the patch to check if the controller's path is absolute before prepending the namespace?

    Thanks.

    April 23rd, 2010 @ 10:50 AM

  6. José Valim
    José Valim
    • Milestone cleared.
    • State changed from committed to open

    So far, we did not support absolute controller paths. Could you please bring this feature request to Rails mailing list?

    April 23rd, 2010 @ 10:53 AM

  7. José Valim
    José Valim
    • State changed from open to hold

    Daniele, any news? Have you brought this topic to discussion in the mailing list?

    April 29th, 2010 @ 11:54 AM

  8. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to Low

    October 15th, 2010 @ 11:01 PM