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.
on 2007-05-15 14:33
on 2007-05-15 16:44
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 => @post.author %> <%= render :partial => 'comment', :collection => @comments %> This gives me a post, a partial for its author, and a partial for each comment. Cheers