# How to define routes for resource that belongs to multiple resources?

**URL:** <https://www.ruby-forum.com/t/how-to-define-routes-for-resource-that-belongs-to-multiple-resources/141159>\
**Category:** Rails\
**Created:** [June 22, 2008, 11:48pm UTC](https://www.ruby-forum.com/t/how-to-define-routes-for-resource-that-belongs-to-multiple-resources/141159 "2008-06-22T23:48:00Z")\
**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:** [June 22, 2008, 11:48pm UTC](https://www.ruby-forum.com/t/how-to-define-routes-for-resource-that-belongs-to-multiple-resources/141159/1 "2008-06-22T23:48:00Z")

</div>

Say I have resource comment that belongs to resources post and blog. I  
know that to nest comment into say, post would look like this:

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

However, if I wanted :comments to also belong to :blogs, how would I  
do that?

---

<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:** [June 23, 2008, 3:03am UTC](https://www.ruby-forum.com/t/how-to-define-routes-for-resource-that-belongs-to-multiple-resources/141159/2 "2008-06-23T03:03:23Z")

</div>

On Jun 22, 5:47 pm, Mike C [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Say I have resource comment that belongs to resources post and blog. I  
> know that to nest comment into say, post would look like this:

What you’re really looking for is called Polymorphic Associations:  
[http://wiki.rubyonrails.org/rails/pages/UnderstandingPolymorphicAssociations](http://wiki.rubyonrails.org/rails/pages/UnderstandingPolymorphicAssociations)

---

<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:** [June 23, 2008, 3:39am UTC](https://www.ruby-forum.com/t/how-to-define-routes-for-resource-that-belongs-to-multiple-resources/141159/3 "2008-06-23T03:39:40Z")

</div>

Thanks a bunch! 🙂

---

<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:** [June 28, 2008, 1:11am UTC](https://www.ruby-forum.com/t/how-to-define-routes-for-resource-that-belongs-to-multiple-resources/141159/4 "2008-06-28T01:11:37Z")

</div>

Actually I just read through that and while it’s useful, I still want  
to know the syntax for defining such relationships.
