# Rendering a Collection in a Partial

**URL:** <https://www.ruby-forum.com/t/rendering-a-collection-in-a-partial/175784>\
**Category:** Rails\
**Created:** [September 19, 2009, 2:42pm UTC](https://www.ruby-forum.com/t/rendering-a-collection-in-a-partial/175784 "2009-09-19T14:42:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [September 19, 2009, 2:42pm UTC](https://www.ruby-forum.com/t/rendering-a-collection-in-a-partial/175784/1 "2009-09-19T14:42:16Z")

</div>

New to rails and having some trouble rendering a partial. Essentially,  
I want the partial to display an index of all the items from another  
model. Do I need to add something to the controller to do this?

projects #show.html.erb  
\<%= render :partial =\> ‘milestones/list’, :collection=\> @milestones  
%\>

milestones #\_list.erb  
\<% @milestones.each do |milestone| %\>

 \<%=h milestone.name %\> \<%=h milestone.date\_start %\> \<%=h milestone.date\_end %\> \<%=h milestone.project\_id %\> \<%= link\_to 'Show', milestone %\> \<%= link\_to 'Edit', edit\_milestone\_path(milestone) %\> \<%= link\_to 'Destroy', milestone, :confirm =\> 'Are you sure?', :method =\> :delete %\> \<% end %\>

It doesn’t give me an error, but neither does it give me the partial.  
If I remove :collection then I get a nil object error.

---

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [September 19, 2009, 3:03pm UTC](https://www.ruby-forum.com/t/rendering-a-collection-in-a-partial/175784/2 "2009-09-19T15:03:20Z")

</div>

2009/9/19 Glenn [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> \<% @milestones.each do |milestone| %\>  
> \<% end %\>
> 
> It doesn’t give me an error, but neither does it give me the partial.  
> If I remove :collection then I get a nil object error.

Have you looked at the html in your browser? View, Page source or  
similar. See whether the html is there. It may be that it is not  
displaying due to invalid html. I presume that show.html.erb is  
generating the table tags?

Colin
