# Nested resources multiple levels deep

**URL:** <https://www.ruby-forum.com/t/nested-resources-multiple-levels-deep/137102>\
**Category:** Rails\
**Created:** [May 8, 2008, 11:11pm UTC](https://www.ruby-forum.com/t/nested-resources-multiple-levels-deep/137102 "2008-05-08T23:11:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![resident\_moron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5daacb/32.png) [@resident\_moron](https://www.ruby-forum.com/u/resident_moron)\
**Post date:** [May 8, 2008, 11:11pm UTC](https://www.ruby-forum.com/t/nested-resources-multiple-levels-deep/137102/1 "2008-05-08T23:11:21Z")

</div>

I’m wondering how or if it is possible to nest a resource more than  
one level.

routes.rb

map.namespace :blog do |blog|  
blog.resources :channels, :has\_many =\> :articles  
end

For example, how could I say that would like each article to have  
nested comments.

map.namespace :blog do |blog|  
blog.resources :channels, :has\_many  
=\> :articles ?? :has\_many :comments  
end

I’m thinking the url would look something like:  
/blog/channel/1/article/1/comment/1

Thanks,

resident moron

---

<div class="post-metadata">

**Author:** ![resident\_moron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5daacb/32.png) [@resident\_moron](https://www.ruby-forum.com/u/resident_moron)\
**Post date:** [May 10, 2008, 6:25pm UTC](https://www.ruby-forum.com/t/nested-resources-multiple-levels-deep/137102/2 "2008-05-10T18:25:45Z")

</div>

There is another way of doing :has\_many that is this way:

map.resources :posts do |post|  
post.resources :comments  
end

This way your route will be something like this:

map.namespace :blog do |blog|  
map.resources :channels do |channel|  
channel.resources :articles do |article|  
article.resources :comments  
end  
end  
end

On May 8, 2008, at 6:10 PM, rails.impaired wrote:

> For example, how could I say that would like each article to have  
> Thanks,
> 
> resident moron

–  
Rafael Gaspar - removed\_email\_address@domain.invalid  
[http://rafaelcanhasblog.com](http://rafaelcanhasblog.com)
