# Render a partial that has assosciations with something else

**URL:** <https://www.ruby-forum.com/t/render-a-partial-that-has-assosciations-with-something-else/172470>\
**Category:** Rails\
**Created:** [July 22, 2009, 1:53am UTC](https://www.ruby-forum.com/t/render-a-partial-that-has-assosciations-with-something-else/172470 "2009-07-22T01:53:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [July 22, 2009, 1:53am UTC](https://www.ruby-forum.com/t/render-a-partial-that-has-assosciations-with-something-else/172470/1 "2009-07-22T01:53:40Z")

</div>

hi,  
Does anyone know how I can render a partial that has an assosciation  
with something else (e.g. render a comments partial in posts-- where the  
comments belong to posts).  
Thanks

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [July 22, 2009, 6:06am UTC](https://www.ruby-forum.com/t/render-a-partial-that-has-assosciations-with-something-else/172470/2 "2009-07-22T06:06:16Z")

</div>

If you have your model associations setup properly you should be able  
to access them using post.comments

For example:

class Post \< ActiveRecord::Base  
has\_many :comments  
end

class Comment \< ActiveRecord::Base  
belongs\_to :post  
end

In \_post.rhtml you can do

\<%= render :partial =\> “comment/comment”, :collection =\> post.comments  
%\>

That assumes you have a partial called \_comment.rhtml in the “comment”  
directory under views.

On Jul 21, 6:53 pm, John M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [July 22, 2009, 9:33pm UTC](https://www.ruby-forum.com/t/render-a-partial-that-has-assosciations-with-something-else/172470/3 "2009-07-22T21:33:12Z")

</div>

Thanks!
