# Render :collection and :partial

**URL:** <https://www.ruby-forum.com/t/render-collection-and-partial/130986>\
**Category:** Rails\
**Created:** [March 4, 2008, 11:56pm UTC](https://www.ruby-forum.com/t/render-collection-and-partial/130986 "2008-03-04T23:56:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e68b1a/32.png) [@Pito](https://www.ruby-forum.com/u/Pito)\
**Post date:** [March 4, 2008, 11:56pm UTC](https://www.ruby-forum.com/t/render-collection-and-partial/130986/1 "2008-03-04T23:56:31Z")

</div>

Does the :collection option on render only work with :partials? Or can  
I call render :collection directly from a controller against a normal  
(non-partial) template? I couldn’t get it to work but maybe I am  
missing something.

---

<div class="post-metadata">

**Author:** ![Pito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e68b1a/32.png) [@Pito](https://www.ruby-forum.com/u/Pito)\
**Post date:** [March 5, 2008, 12:30am UTC](https://www.ruby-forum.com/t/render-collection-and-partial/130986/2 "2008-03-05T00:30:01Z")

</div>

Pito, we’d need to see some code to be more helpful.

Try changing the name of the partial to match the model / variable  
names.

---

<div class="post-metadata">

**Author:** ![Pito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e68b1a/32.png) [@Pito](https://www.ruby-forum.com/u/Pito)\
**Post date:** [March 5, 2008, 2:46am UTC](https://www.ruby-forum.com/t/render-collection-and-partial/130986/3 "2008-03-05T02:46:40Z")

</div>

Pito wrote:

> Does the :collection option on render only work with :partials? Or can  
> I call render :collection directly from a controller against a normal  
> (non-partial) template? I couldn’t get it to work but maybe I am  
> missing something.

Rendering collections is only meant to be done with partials.

–  
[http://www.5valleys.com/](http://www.5valleys.com/)  
[http://www.workingwithrails.com/person/8078](http://www.workingwithrails.com/person/8078)

---

<div class="post-metadata">

**Author:** ![Pito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e68b1a/32.png) [@Pito](https://www.ruby-forum.com/u/Pito)\
**Post date:** [March 5, 2008, 2:38am UTC](https://www.ruby-forum.com/t/render-collection-and-partial/130986/4 "2008-03-05T02:38:27Z")

</div>

:collection only works on partials in this instance.

You can streamline your render partial calls by using instance  
variable names that match your class and partial name

e.g. \<%= render :partial =\> @posts %\> would render the collection  
@posts in a partial called \_post.html.erb (Rails 2.0.2) ( i think)

If you wanted to render a colleciton in a normal template either  
create the partial call within it or use the each method to iterate  
the collection. e.g.  
@posts.each do |post|  
…  
end

With more AJAX stuff it makes sense to use partials more often so you  
can reload sections of your view easily from rjs.
