Forum: Ruby on Rails Partials - when to use :object =>

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
753038ae16700c0fd9a5e1d2e80f68f6?d=identicon&s=25 (Guest)
on 2007-05-15 14:33
(Received via mailing list)
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.
Bc6c0fd7296921fb7eae416f7c9e86a1?d=identicon&s=25 David Richards (Guest)
on 2007-05-15 16:44
(Received via mailing list)
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:

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

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

This topic is locked and can not be replied to.