Lee.Longmore-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-May-15 12:32 UTC
Partials - when to use :object =>
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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---