This project is archived and is in readonly mode.
Route to root of a namespace
Reported by James | February 4th, 2010 @ 06:41 PM
In Rails 2.3.x, you could do the following:
map.namespace :admin do |admin|
admin.root :controller => "admin"
end
It appears this functionality is missing in the Rails 3 router. Neither of the following match /admin:
namespace :admin do
root :to => 'admin#index'
match '' => 'admin#index'
end
Comments and changes to this ticket
-
josh February 5th, 2010 @ 03:00 PM
- State changed from new to invalid
I didn't realize that worked, but thats not the purpose of "root". The original intent was to provide a convention "root_url" named route plugins, etc could depend on. It doesn't make sense in the nested context.
-
James February 5th, 2010 @ 04:58 PM
Josh,
Previously it provided the "admin_root_url" named route, which seems to me like a great convention as it kept everything (including the index) within the context of admin. Even if you do consider this an "invalid" request, how would you recommend defining the root of a namespace?
James
-
Mark Connell February 8th, 2010 @ 02:09 PM
This does actually work in the new DSL, however you have to explicitly set the namespace in the
:to
In rails 2 if you had an Admin::Posts controller the following would have worked:
# http://localhost:3000/admin map.namespace :admin do |admin| admin.root :controller => 'posts' end
And the admin.root automagically picked up the namespace context. To do the same in the new routing, the following examples work:
# http://localhost:3000/admin namespace :admin do root :to => "admin/posts#index" end # http://localhost:3000/admin namespace :admin do root :to => "Admin::Posts#index" end
-
James February 8th, 2010 @ 11:21 PM
Is there any reason we should need to explicitly set the namespace in the :to when we're within the namespace block? Seems like it should know about the namespace context and avoid duplication.
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>