# Partials - when to use :object =\>

**URL:** <https://www.ruby-forum.com/t/partials-when-to-use-object/104213>\
**Category:** Rails\
**Created:** [May 15, 2007, 2:33pm UTC](https://www.ruby-forum.com/t/partials-when-to-use-object/104213 "2007-05-15T14:33:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 15, 2007, 2:33pm UTC](https://www.ruby-forum.com/t/partials-when-to-use-object/104213/1 "2007-05-15T14:33:55Z")

</div>

When should I use “:object =\>” or “:collection =\>” to pass an object  
reference to a partial vs reference an instance variable directly with  
the partial?

I would value best practice/opinions/pros/cons on this.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 15, 2007, 4:44pm UTC](https://www.ruby-forum.com/t/partials-when-to-use-object/104213/2 "2007-05-15T16:44:15Z")

</div>

I use collection to loop through a list. So, render :partial =\>  
‘comment’, :collection =\> @comments saves me a few lines of code over  
putting a loop inside the view or partial. :object would be useful  
when showing just a single record. So, maybe something like this  
makes sense:

# \<%= @post.title %\>
\<%= @post.body %\> \<%= render :partial =\> 'author', :object =\> @post.author %\> \<%= render :partial =\> 'comment', :collection =\> @comments %\>

This gives me a post, a partial for its author, and a partial for each  
comment.

Cheers
