This project is archived and is in readonly mode.
In new router, collection doesn't add name of the parent resource
-
Timo Mika Gläßer
I think what is actually wrong in your example is the nesting of
collection do resources :genres endwhere is should just read
resources :books do resources :genres endBut I have a similiar problem with the methods not being generated. ;)
-
xHire
It might seem so, but your suggestion generates URLs like
/books/:book_id/genres/new(.:format)but that's definitely not what I wanted. ;c) Anyway the problem is not that it is not working (because it is) but that it doesn't generate correct names of the routes. -
Timo Mika Gläßer
Ok, sorry my misunderstanding. Did you consider using the option "namespace => :books"? See http://www.slideshare.net/mbleigh/upgrading-to-rails-3 at slide 25.
-
xHire
Yes, to be able to continue in development of my application I was forced to use
scope :as => :books. But that's not solution, that's just a hack, a temporary workaround which will be dropped as soon as this bug will be fixed. :c)If it could be done with simple nesting, why should I look for any complicated solutions (as namespace is)?
-
Andrew White
- State changed from new to wontfix
- Importance changed from to Low
The resource scopes collection, member and new aren't designed to have resources calls inside them - there are no tests for this functionality so it is essentially undefined. The reason it sort of works is that the mapper will automatically wrap the resources call inside a nested block as a convenience. It's better to use the proper api:
resources :books namespace :books, :module => nil do resources :genres endYou can leave off the :module => nil if you'd prefer the resources controller to be books/genres.
-
xHire
The resource scopes collection, member and new aren't designed to have resources calls inside them - there are no tests for this functionality so it is essentially undefined.
If the only problem is that my use case wasn't intended to exist, but isn't unwanted, would be proper patch for this issue accepted?
I just want to know if I should use my current workaround (with scope which currently more suits my needs than your suggestion) or if I could try to fix this in Rails.
-
Andrew White
The concept of nested resources implies ownership by the parent therefore the use case isn't intended to exist, so I'd use whatever alternative method of generating your routes you prefer.
-
xHire
OK, thank you.