# Partials, Layouts and Collections

**URL:** <https://www.ruby-forum.com/t/partials-layouts-and-collections/126823>\
**Category:** Rails\
**Created:** [January 22, 2008, 3:56pm UTC](https://www.ruby-forum.com/t/partials-layouts-and-collections/126823 "2008-01-22T15:56:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85e7bf/32.png) [@ant](https://www.ruby-forum.com/u/ant)\
**Post date:** [January 22, 2008, 3:56pm UTC](https://www.ruby-forum.com/t/partials-layouts-and-collections/126823/1 "2008-01-22T15:56:40Z")

</div>

Hi All,  
I am trying to make use of the new render partial functionality where  
in the index view I have

\<%= render :partial =\> @people%\> #in rails 2.0 it detects this as a  
collection

and in the show

\<%= render :partial =\> @person%\> #in rails 2.0 it detects this as an  
object

The \_person.html.erb partial is

\<%=h person.first\_name %\> \<%=h person.last\_name %\>

However I would like in the index view to add links to show or  
destroy and in the show view add an edit link.

I tried to use the new layout for partials feature

\<%= render :partial =\> @people, :layout =\> ‘index’%\>  
\<%= render :partial =\> @people, :layout =\> ‘show’%\>

where the \_index.html.erb contained the show and destroy links and the  
\_show.html.erb contains the edit link. However for the layout it only  
seems to be rendered once for a collection not once for each object in  
the collection. Am I doing something wrong or is there a neat way  
round this.

Thanks

Anthony

---

<div class="post-metadata">

**Author:** ![ant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85e7bf/32.png) [@ant](https://www.ruby-forum.com/u/ant)\
**Post date:** [January 22, 2008, 6:42pm UTC](https://www.ruby-forum.com/t/partials-layouts-and-collections/126823/2 "2008-01-22T18:42:10Z")

</div>

you’ll need to place the @people collection into a “for” statment and  
iterate through them, you’ll see similar contructs in the  
index.html.erb if you scaffold.

\<% for person in @people %\>  
\<%= h(person.first\_name) %\>

etc…

\<% end %\>
