# Iterating through a collection using partials

**URL:** <https://www.ruby-forum.com/t/iterating-through-a-collection-using-partials/87552>\
**Category:** Rails\
**Created:** [March 3, 2007, 7:19pm UTC](https://www.ruby-forum.com/t/iterating-through-a-collection-using-partials/87552 "2007-03-03T19:19:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [March 3, 2007, 7:19pm UTC](https://www.ruby-forum.com/t/iterating-through-a-collection-using-partials/87552/1 "2007-03-03T19:19:51Z")

</div>

This should be straightforward but a search hasn’t helped:

I want to convert this:  
\<% for post in @posts %\>

\<%= link\_to "#{post.title}" %\>

posted by \<%= link\_to "#{post.person.name}" %\>
  

\<%= h(post.body) %\>

  

\<% end %\>

into THIS:

\<% for post in @posts %\>  
\<%= render :partial =\> ‘postblock’%  
\<% end %\>

but just moving the PostBlock div into \_postblock.rhtml gives an invalid  
action for “post.” How can I cleanly separate this? I’ve also tried  
using :collection =\> @posts but the documentation on :collection is very  
poor. Thanks!

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [March 3, 2007, 7:26pm UTC](https://www.ruby-forum.com/t/iterating-through-a-collection-using-partials/87552/2 "2007-03-03T19:26:59Z")

</div>

It was a naming convention problem. Since the passed object is  
automagically named the same thing as the partial, penaming the partial  
to “\_post.rhtml” works:

\<%= render :partial =\> ‘post’, :collection =\> @posts %\>

This information came from page 511 in AWDwRv2
