# Nested Resources And Creating URL Problemos

**URL:** <https://www.ruby-forum.com/t/nested-resources-and-creating-url-problemos/123112>\
**Category:** Rails\
**Created:** [December 14, 2007, 3:59am UTC](https://www.ruby-forum.com/t/nested-resources-and-creating-url-problemos/123112 "2007-12-14T03:59:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/59ef9b/32.png) [@johnk](https://www.ruby-forum.com/u/johnk)\
**Post date:** [December 14, 2007, 3:59am UTC](https://www.ruby-forum.com/t/nested-resources-and-creating-url-problemos/123112/1 "2007-12-14T03:59:03Z")

</div>

I am doing the following:  
link\_to “delete my avatar”, user\_pictures\_path(:user\_id =\> @user, :id =\>  
@  
user.pictures.last), :method =\> :delete

and it is creating the following link:

[http://127.0.0.1:3000/users/4/pictures?id=10](http://127.0.0.1:3000/users/4/pictures?id=10)

Two things:

1. shouldn’t it create the following URL?  
[http://127.0.0.1:3000/users/4/pictures/10](http://127.0.0.1:3000/users/4/pictures/10)

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

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

Thanks 🙂

–  
John K.  
removed\_email\_address@domain.invalid

Blog: [http://www.kopanas.com](http://www.kopanas.com)  
Conference: [http://www.cusec.net](http://www.cusec.net)  
Twits: [http://www.twitter.com/kopanas](http://www.twitter.com/kopanas)

---

<div class="post-metadata">

**Author:** ![johnk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/59ef9b/32.png) [@johnk](https://www.ruby-forum.com/u/johnk)\
**Post date:** [December 14, 2007, 4:34am UTC](https://www.ruby-forum.com/t/nested-resources-and-creating-url-problemos/123112/2 "2007-12-14T04:34:07Z")

</div>

If you are using nested routes like this:

map.resources :users do |user|  
user.resources :pictures  
end

Then you should be able to do this:

link\_to “delete my avatar”, user\_pictures\_path(@user,  
@user.pictures.last), :method =\> :delete

Michael B.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![johnk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/59ef9b/32.png) [@johnk](https://www.ruby-forum.com/u/johnk)\
**Post date:** [December 14, 2007, 5:01am UTC](https://www.ruby-forum.com/t/nested-resources-and-creating-url-problemos/123112/3 "2007-12-14T05:01:36Z")

</div>

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?

On Dec 13, 2007 10:33 PM, Michael B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Michael B.  
> [http://127.0.0.1:3000/users/4/pictures?id=10](http://127.0.0.1:3000/users/4/pictures?id=10)
> 
> >

–  
John K.  
removed\_email\_address@domain.invalid

Blog: [http://www.kopanas.com](http://www.kopanas.com)  
Conference: [http://www.cusec.net](http://www.cusec.net)  
Twits: [http://www.twitter.com/kopanas](http://www.twitter.com/kopanas)

---

<div class="post-metadata">

**Author:** ![johnk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/59ef9b/32.png) [@johnk](https://www.ruby-forum.com/u/johnk)\
**Post date:** [December 14, 2007, 5:15am UTC](https://www.ruby-forum.com/t/nested-resources-and-creating-url-problemos/123112/4 "2007-12-14T05:15:03Z")

</div>

I think you want this instead

user\_picture\_path(@user, @user.pictures.last) \<== Note: singular form  
of ‘picture’ in the method name.
