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.

router scope does not behave as documented

#5046

The router documentation (http://guides.rails.info/routing.html#prefixing-the-named-route-hel...) states the following:

To prefix a group of routes, use :as with scope:

scope "admin", :as => "admin" do
  resources :photos, :accounts
end

However, when putting this code into config/routes.rb and executing rake:routes, the following is shown:

~/Code/wombat[master]% rake routes        
(in /home/rob/Code/wombat)
           GET    /admin/photos(.:format)            {:controller=>"photos", :action=>"index"}
           POST   /admin/photos(.:format)            {:controller=>"photos", :action=>"create"}
           GET    /admin/photos/new(.:format)        {:controller=>"photos", :action=>"new"}
           GET    /admin/photos/:id(.:format)        {:controller=>"photos", :action=>"show"}
           PUT    /admin/photos/:id(.:format)        {:controller=>"photos", :action=>"update"}
           DELETE /admin/photos/:id(.:format)        {:controller=>"photos", :action=>"destroy"}
           GET    /admin/photos/:id/edit(.:format)   {:controller=>"photos", :action=>"edit"}
           GET    /admin/accounts(.:format)          {:controller=>"accounts", :action=>"index"}
    admins POST   /admin/accounts(.:format)          {:controller=>"accounts", :action=>"create"}
 new_admin GET    /admin/accounts/new(.:format)      {:controller=>"accounts", :action=>"new"}
           GET    /admin/accounts/:id(.:format)      {:controller=>"accounts", :action=>"show"}
           PUT    /admin/accounts/:id(.:format)      {:controller=>"accounts", :action=>"update"}
     admin DELETE /admin/accounts/:id(.:format)      {:controller=>"accounts", :action=>"destroy"}
edit_admin GET    /admin/accounts/:id/edit(.:format) {:controller=>"accounts", :action=>"edit"}
~/Code/wombat[master]%

Instead of appending a path prefix, so for example edit_admin_account etc, it appears to be completely messing up the path names.

Reported by Rob Greenwood · July 5th, 2010 @ 01:12 PM

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

Activity

  1. José Valim
    José Valim
    • Assigned user set to José Valim
    • State changed from new to invalid
    • Milestone cleared.
    • Importance changed from to Low

    I'm using Rails master and it works as expected (and documented). You are probably using the old version where :as was called :name_prefix.

    July 5th, 2010 @ 02:18 PM

  2. Rob Greenwood
    Rob Greenwood

    Yep, you're right. Obviously this change must have happened after beta4.

    Wombat::Application.routes.draw do |map|
    
      # Admin Routes
      scope :module => "admin", :name_prefix => "admin", :constraints => { :subdomain => "admin" } do
        root :to => 'dashboard#welcome'
      end
    
    end
    

    Works fine

    July 5th, 2010 @ 02:31 PM

  3. Jeremy Kemper