# Nested Resources

**URL:** <https://www.ruby-forum.com/t/nested-resources/108288>\
**Category:** Rails\
**Created:** [July 1, 2007, 7:22pm UTC](https://www.ruby-forum.com/t/nested-resources/108288 "2007-07-01T19:22:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 1, 2007, 7:22pm UTC](https://www.ruby-forum.com/t/nested-resources/108288/1 "2007-07-01T19:22:53Z")

</div>

I have a user model that can have one album. Album can have multiple  
photos. How do I create nested resources for these three models? How  
do you avoid nesting more than two levels?

All the examples I have seen only have nesting with two levels. TIA.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 1, 2007, 8:08pm UTC](https://www.ruby-forum.com/t/nested-resources/108288/2 "2007-07-01T20:08:59Z")

</div>

On 7/1/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a user model that can have one album. Album can have multiple  
> photos. How do I create nested resources for these three models? How  
> do you avoid nesting more than two levels?
> 
> All the examples I have seen only have nesting with two levels. TIA.

You can nest as deeply as you want.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 2, 2007, 5:34am UTC](https://www.ruby-forum.com/t/nested-resources/108288/3 "2007-07-02T05:34:44Z")

</div>

I have:

map.resources :users do |user|  
user.resource :album do |album|  
album.resources :photos  
end  
end

Should I use the singular resource for my case?Thanks.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 2, 2007, 5:47am UTC](https://www.ruby-forum.com/t/nested-resources/108288/4 "2007-07-02T05:47:53Z")

</div>

removed\_email\_address@domain.invalid wrote:

> I have:
> 
> map.resources :users do |user|  
> user.resource :album do |album|  
> album.resources :photos  
> end  
> end
> 
> Should I use the singular resource for my case?Thanks.

From the ri documentation for “resource”:

```
 See map.resources for general conventions. These are the main
 differences:

   - a singular name is given to map.resource. The default 

```

controller name is taken from the singular name.  
- To specify a custom plural name, use the :plural option. There  
is no :singular option  
- No default index, new, or create routes are created for the  
singleton resource controller.  
- When nesting singleton resources, only the singular name is  
used as the path prefix (example: ‘account/messages/1’)
