# REST and nested resources more than one level?

**URL:** <https://www.ruby-forum.com/t/rest-and-nested-resources-more-than-one-level/90904>\
**Category:** Rails\
**Created:** [April 2, 2007, 9:49pm UTC](https://www.ruby-forum.com/t/rest-and-nested-resources-more-than-one-level/90904 "2007-04-02T21:49:37Z")\
**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:** [April 2, 2007, 9:49pm UTC](https://www.ruby-forum.com/t/rest-and-nested-resources-more-than-one-level/90904/1 "2007-04-02T21:49:37Z")

</div>

Is it possible to nest a resource more than a single level? For  
example something like this:

map.resources :articles do |article|  
article.resources :comments do |comment|  
comment.resources :foo  
end  
end

–  
Sterling A.

> **[sterlinganderson.net –](https://sterlinganderson.net/)**

sterling\_anderson[at][mac.com](http://mac.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:** [April 2, 2007, 10:26pm UTC](https://www.ruby-forum.com/t/rest-and-nested-resources-more-than-one-level/90904/2 "2007-04-02T22:26:41Z")

</div>

Don’t see why not. Have you tried it and had problems?

Jason

---

<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:** [April 3, 2007, 1:33am UTC](https://www.ruby-forum.com/t/rest-and-nested-resources-more-than-one-level/90904/3 "2007-04-03T01:33:25Z")

</div>

Yes you can, but you may want to take a look at this link[1] which  
suggests against doing so.

[1] [Buckblog: Nesting resources](http://weblog.jamisbuck.org/2007/2/5/nesting-resources)

## Nelson

Basedex - A Collaborative Index to organize and collect everything  
related to Ruby on Rails  
[http://blazingrails.basedex.com/index/8](http://blazingrails.basedex.com/index/8)

sterling wrote:

> Is it possible to nest a resource more than a single level? For  
> example something like this:
> 
> map.resources :articles do |article|  
> article.resources :comments do |comment|  
> comment.resources :foo  
> end  
> end
> 
> –  
> Sterling A.  
> [http://sterlinganderson.net/](http://sterlinganderson.net/)  
> sterling\_anderson[at][mac.com](http://mac.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:** [April 3, 2007, 8:39pm UTC](https://www.ruby-forum.com/t/rest-and-nested-resources-more-than-one-level/90904/4 "2007-04-03T20:39:54Z")

</div>

The scenario explained in that article is pretty specific. There are  
many instances where nesting further than a single level deep is  
necessary. For example, if you were creating CRM system, you may have  
a structure like:

map.resources :customers do |customers|  
customers.resources :ships do |ships|  
ships.resources :accounts  
end  
end

Here, each customer can have many shipping addresses and for each  
shipping address there can be many ship accounts (ups, fedex, etc). In  
addition, a shipping account is only associated with a single shipping  
address and therefore should only be referenced through the shipping  
address.

On Apr 2, 7:33 pm, Nelson H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
