Topic: Yet another restful routes question

Maybe I'm just tired an need to take a break.. but if you have this in your routes:

  map.resources :users do |users|
         users.resources :colors
  map.resources :users
  map.resources :colors

and /users/1/colors gives you the data you want, shouldn't you be able to generate the url like this:

<%= link_to "My Colors", colors_path(current_user)%>

I would think it's pretty straight forward, but I'm getting an error that says:

You have a nil object when you didn't expect it!
The error occurred while evaluating nil.to_sym

That happens even if I hard code it as colors_path(1) so I'm sure it's not an error with current_user being nil.  Where am I going wrong?

Turning that link into color_path(1) gives me color/1 instead of users/1/colors


Re: Yet another restful routes question

Looks like the named routes for the latter :users is overriding the nested one. You should add a name_prefix so you can differentiate the two:

  map.resources :users do |users|
    users.resources :colors, :name_prefix => 'user_'

Then you can do "user_colors_path(current_user)"

Railscasts - Free Ruby on Rails Screencasts

Re: Yet another restful routes question

That works!  But I thought the routes file was stacked in order of importance?  I could have sworn I had also tried removing both map.resources :users and map.resources :colors..

Anyway, thanks very much for the assistance!!!