Imagine a movie-rental website. Sensible REST urls might look like
this:
/movies/51
...and on the business side:
/rentals
/customers
To see the rentals for a particular customer or movie:
/customers/12/rentals
/movies/29/rentals
Unfortunately, adding the last two breaks routing with a cryptic error:
new_movie_url failed to generate from {:controller=>"movies",
:action=>"new"}, expected: {:controller=>"movies",
:action=>"new"},
diff: {}
Here''s the routes.rb:
map.resources :movies do |movies|
movies.resources :rentals
end
map.resources :customers do |customers|
customers.resources :rentals
end
map.resources :rentals do |rentals|
rentals.resources :movies
end
The last resource map now makes new_movie_path() expect to receive a
Rental id. So, the cheap way to fix this is to always call
new_movie_path(1) instead, but it''s a bad hack. What''s the
"right way"
to do these kinds of routes?
It also seems like we should have a better error message in place for
this kind of scenario. Throwing an exception that says I''ve passed all
of the right parameters is crazy.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---