This project is archived and is in readonly mode.
shallow nesting of resource routes does not respect namespace
Reported by Jason M Jones | November 11th, 2008 @ 06:41 PM | in 2.x
It appears that when using shallow => true for nested resource routes within a namespace, the namespace is not being considered for the shallow routes.
If I describe nested routes within a namespace as follows:
map.namespace :admin do |admin|
admin.resources :parents do |parent|
parent.resources :children
end
end
I will get the following routes when I run rake
routes
:
admin_parents GET /admin/parents {:controller=>"admin/parents", :action=>"index"}
formatted_admin_parents GET /admin/parents.:format {:controller=>"admin/parents", :action=>"index"}
POST /admin/parents {:controller=>"admin/parents", :action=>"create"}
POST /admin/parents.:format {:controller=>"admin/parents", :action=>"create"}
new_admin_parent GET /admin/parents/new {:controller=>"admin/parents", :action=>"new"}
formatted_new_admin_parent GET /admin/parents/new.:format {:controller=>"admin/parents", :action=>"new"}
edit_admin_parent GET /admin/parents/:id/edit {:controller=>"admin/parents", :action=>"edit"}
formatted_edit_admin_parent GET /admin/parents/:id/edit.:format {:controller=>"admin/parents", :action=>"edit"}
admin_parent GET /admin/parents/:id {:controller=>"admin/parents", :action=>"show"}
formatted_admin_parent GET /admin/parents/:id.:format {:controller=>"admin/parents", :action=>"show"}
PUT /admin/parents/:id {:controller=>"admin/parents", :action=>"update"}
PUT /admin/parents/:id.:format {:controller=>"admin/parents", :action=>"update"}
DELETE /admin/parents/:id {:controller=>"admin/parents", :action=>"destroy"}
DELETE /admin/parents/:id.:format {:controller=>"admin/parents", :action=>"destroy"}
admin_parent_children GET /admin/parents/:parent_id/children {:controller=>"admin/children", :action=>"index"}
formatted_admin_parent_children GET /admin/parents/:parent_id/children.:format {:controller=>"admin/children", :action=>"index"}
POST /admin/parents/:parent_id/children {:controller=>"admin/children", :action=>"create"}
POST /admin/parents/:parent_id/children.:format {:controller=>"admin/children", :action=>"create"}
new_admin_parent_child GET /admin/parents/:parent_id/children/new {:controller=>"admin/children", :action=>"new"}
formatted_new_admin_parent_child GET /admin/parents/:parent_id/children/new.:format {:controller=>"admin/children", :action=>"new"}
edit_admin_parent_child GET /admin/parents/:parent_id/children/:id/edit {:controller=>"admin/children", :action=>"edit"}
formatted_edit_admin_parent_child GET /admin/parents/:parent_id/children/:id/edit.:format {:controller=>"admin/children", :action=>"edit"}
admin_parent_child GET /admin/parents/:parent_id/children/:id {:controller=>"admin/children", :action=>"show"}
formatted_admin_parent_child GET /admin/parents/:parent_id/children/:id.:format {:controller=>"admin/children", :action=>"show"}
PUT /admin/parents/:parent_id/children/:id {:controller=>"admin/children", :action=>"update"}
PUT /admin/parents/:parent_id/children/:id.:format {:controller=>"admin/children", :action=>"update"}
DELETE /admin/parents/:parent_id/children/:id {:controller=>"admin/children", :action=>"destroy"}
DELETE /admin/parents/:parent_id/children/:id.:format {:controller=>"admin/children", :action=>"destroy"}
This seems to me to be the proper, having admin before every route.
On the other hand, if I take the same resource routes, and make them shallow:
map.namespace :admin do |admin|
admin.resources :parents, :shallow => true do |parent|
parent.resources :children
end
end
Then when running rake routes
I get the following
routes:
admin_parents GET /admin/parents {:controller=>"admin/parents", :action=>"index"}
formatted_admin_parents GET /admin/parents.:format {:controller=>"admin/parents", :action=>"index"}
POST /admin/parents {:controller=>"admin/parents", :action=>"create"}
POST /admin/parents.:format {:controller=>"admin/parents", :action=>"create"}
new_admin_parent GET /admin/parents/new {:controller=>"admin/parents", :action=>"new"}
formatted_new_admin_parent GET /admin/parents/new.:format {:controller=>"admin/parents", :action=>"new"}
edit_parent GET /parents/:id/edit {:controller=>"admin/parents", :action=>"edit"}
formatted_edit_parent GET /parents/:id/edit.:format {:controller=>"admin/parents", :action=>"edit"}
parent GET /parents/:id {:controller=>"admin/parents", :action=>"show"}
formatted_parent GET /parents/:id.:format {:controller=>"admin/parents", :action=>"show"}
PUT /parents/:id {:controller=>"admin/parents", :action=>"update"}
PUT /parents/:id.:format {:controller=>"admin/parents", :action=>"update"}
DELETE /parents/:id {:controller=>"admin/parents", :action=>"destroy"}
DELETE /parents/:id.:format {:controller=>"admin/parents", :action=>"destroy"}
parent_children GET /parents/:parent_id/children {:controller=>"admin/children", :action=>"index"}
formatted_parent_children GET /parents/:parent_id/children.:format {:controller=>"admin/children", :action=>"index"}
POST /parents/:parent_id/children {:controller=>"admin/children", :action=>"create"}
POST /parents/:parent_id/children.:format {:controller=>"admin/children", :action=>"create"}
new_parent_child GET /parents/:parent_id/children/new {:controller=>"admin/children", :action=>"new"}
formatted_new_parent_child GET /parents/:parent_id/children/new.:format {:controller=>"admin/children", :action=>"new"}
edit_child GET /children/:id/edit {:controller=>"admin/children", :action=>"edit"}
formatted_edit_child GET /children/:id/edit.:format {:controller=>"admin/children", :action=>"edit"}
child GET /children/:id {:controller=>"admin/children", :action=>"show"}
formatted_child GET /children/:id.:format {:controller=>"admin/children", :action=>"show"}
PUT /children/:id {:controller=>"admin/children", :action=>"update"}
PUT /children/:id.:format {:controller=>"admin/children", :action=>"update"}
DELETE /children/:id {:controller=>"admin/children", :action=>"destroy"}
DELETE /children/:id.:format {:controller=>"admin/children", :action=>"destroy"}
It seems to me that shallow resource routes should take into account the namespace which they are in, and only make them shallow for that namespace, not globally to the root of the rails app.
I have attached the app I created to illustrate this problem.
Comments and changes to this ticket
-
Jason M Jones January 20th, 2009 @ 10:33 PM
To me it seems like a bug. Some things still stay under the namespace, others do not. It seems like an unintended consequence of the new feature. For instance, lets say I have two resource controllers
- TestsController
- Admin::TestsController
I could then have routes
map.namespace :admin do |admin| admin.resources :tests, :shallow => true do |parent|
parent.resources :comments
end end
map.resources :tests
I would have conflicts in my routes between Admin::TestsController and TestsController, where with namespaces, I should be able to address each seperately.
-
Ben Lambert January 27th, 2009 @ 06:42 PM
This has been driving me nuts, definitely a bug. I'm going to have to un-dry my routes.rb to work around this.
map.namespace :admin, :shallow => true do |admin|
admin.resources :restaurants, do |restaurant| restaurant.resources :campaigns restaurant.resources :locations end
end
I should be able to view a campaign via admin/restaurants/1/campaigns/1 or admin/campaigns/1
However as it stands now, I can view a restaurant via admin/restaurants/1
But the campaigns are completely removed from the namespace, and can be accessed only via: /restaurants/1/campaigns/1 or /campaigns/1
It really defeats the purpose of having a namespace in the first place.
-
Ben Lambert January 27th, 2009 @ 06:48 PM
I wish Lighthouse came with a preview or edit button. Let me try that again.
This has been driving me nuts, definitely a bug. I'm going to have > to un-dry my routes.rb to work around this.
@@@ map.namespace :admin, :shallow => true do |admin| admin.resources :restaurants, do |restaurant|
restaurant.resources :campaigns restaurant.resources :locations
end end @@@
I should be able to view a campaign via @@@admin/restaurants/1/campaigns/1@@@ or @@@admin/campaigns/1@@@
However as it stands now, I can view a restaurant via @@@admin/restaurants/1@@@
The campaigns are completely removed from the namespace, and can be accessed only via @@@/restaurants/1/campaigns/1@@@ or @@@/campaigns/1@@@
It really defeats the purpose of having a namespace in the first place.
-
Ben Lambert January 27th, 2009 @ 06:53 PM
Third time lucky:
This has been driving me nuts, definitely a bug. I'm going to have to un-dry my routes.rb to work around this.
map.namespace :admin, :shallow => true do |admin| admin.resources :restaurants, do |restaurant| restaurant.resources :campaigns restaurant.resources :locations end end
I should be able to view a campaign via
admin/restaurants/1/campaigns/1 @@@ or
admin/campaigns/1
However as it stands now, I can view a restaurant via
admin/restaurants/1
but the campaigns are completely removed from the namespace, and can be accessed only via
/restaurants/1/campaigns/1
or
/campaigns/1
It really defeats the purpose of having a namespace in the first place.
-
David Reese February 7th, 2009 @ 05:08 PM
+1, fwiw -- my routes are a mess because of this.
i'd look at it myself but the routing code makes my head hurt.
-
Tom Stuart March 7th, 2009 @ 10:49 PM
- Assigned user changed from Pratik to Michael Koziarski
-
Repository March 7th, 2009 @ 10:51 PM
- State changed from new to resolved
(from [5c87e9adddc22703a3dbbb785e32fafe0e91ce78]) Ensure shallow routes respects namespace [#1356 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...
-
csnk May 18th, 2011 @ 08:18 AM
We are the professional shirts manufacturer, shirts supplier, shirts factory, custom shirts.
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>
People watching this ticket
Attachments
Referenced by
- 1356 shallow nesting of resource routes does not respect namespace (from [5c87e9adddc22703a3dbbb785e32fafe0e91ce78]) Ensure ...