Forum: Ruby on Rails Route generation and clashes

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E4923a4540eb242fbdb2898e4ebfa0bb?d=identicon&s=25 D. Scott Brown (Guest)
on 2006-12-31 00:33
(Received via mailing list)
Imagine a movie-rental website. Sensible REST urls might look like


...and on the business side:

To see the rentals for a particular customer or movie:

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

  map.resources :customers do |customers|
    customers.resources :rentals

  map.resources :rentals do |rentals|
    rentals.resources :movies

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.
This topic is locked and can not be replied to.