Nested Resources And Creating URL Problemos

I am doing the following:

link_to “delete my avatar”, user_pictures_path(:user_id => @user, :id =>, :method => :delete

and it is creating the following link:

Two things:

  1. shouldn’t it create the following URL?

i.e. not the ?id=10 but just /10?

  1. Is there a cleaner way of building the url?

Thanks :slight_smile:

If you are using nested routes like this:

map.resources :users do |user|

user.resources :pictures


Then you should be able to do this:

link_to “delete my avatar”, user_pictures_path(@user,, :method => :delete

Michael Bleigh

When I do that I get the following error:

undefined method `has_key?' for #<Picture:0x266d170>

when I do it my way I do not get an error but the id of the picture gets passed in querystring instead of URL… any suggestions peeps?

I think you want this instead

user_picture_path(@user, <== Note: singular form of 'picture' in the method name.