Forum: Ruby on Rails Resolving named route conflicts

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D. Scott B. (Guest)
on 2006-12-31 01:33
(Received via mailing list)
Let's say you're building a movie rental website. You have customers,
movies, and rentals to manage. REST style urls might look like this:

/customers/4
/movies/15
/rentals

You'd probably also want administrators to be able to view all of the
rentals done by a particular customer, and other similar details:

/customers/4/rentals
/movies/15/rentals
/rentals/529/customers

Except you can't, at least not as far as I understand route generation.
Looking at routes.rb for the example:

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

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

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

These map blocks introduce ambiguity about what rental_url(1,5) should
generate - /movies/1/rentals/5 or /customers/1/movies/5. The error
message pointing this out sucks (rentals_url failed to generate from
{:controller=>"rentals", :action=>"index"}, expected:
{:controller=>"rentals", :action=>"index"}, diff: {}), but I digress.

Instead of throwing an error in this kind of situation (which I imagine
would be relatively common), why not take a named route like
customer_rentals_url(1,5) or new_movie_rental_url(1)?

There may be a very good reason why not, and I'm new here, so bear with
me. :)
This topic is locked and can not be replied to.