Phillip Koebbe
2008-Sep-30 14:54 UTC
:locals vs. instance variable in partials ... best practice?
I''ve been vacillating between using the :locals hash and instance variables when passing data to partials. Is there a valid reason to use one over the other? What could be considered a best practice in the Rails community? I did some googling but didn''t turn anything up. Peace. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Robby Russell
2008-Sep-30 15:35 UTC
Re: :locals vs. instance variable in partials ... best practice?
On Tue, Sep 30, 2008 at 7:54 AM, Phillip Koebbe <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I''ve been vacillating between using the :locals hash and instance > variables when passing data to partials. Is there a valid reason to use > one over the other? What could be considered a best practice in the > Rails community? I did some googling but didn''t turn anything up. >As a general rule of thumb, you''ll want to be conservative when it comes to scoping your variables. In my opinion, it''s best to use locals and not rely on an instance variable. Cheers, Robby -- Robby Russell Chief Evangelist, Partner PLANET ARGON, LLC design // development // hosting http://www.planetargon.com/ http://www.robbyonrails.com/ aim: planetargon +1 503 445 2457 +1 877 55 ARGON [toll free] +1 815 642 4068 [fax] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dwhsix
2008-Sep-30 16:39 UTC
Similarly: partial w/ collection vs iteration? (was Re: :locals vs. instance variable in partials ... best practice?)
In a similar vein... I''ve always wondered if there''s a performance (or other) difference between using an iterating partial (e.g. with :collection =>) vs. an explicit iterator. For example: <%= render :partial => ''item'', :collection => @items %> vs. <% @items.each do |i| %> <%= h i.name %> <% end %> (I suppose there''s also the case of writing an explicit iteration but using a partial inside the iteration) I assume (but haven''t tested) that the latter case is more performant; but using the iterating partial feels more ''rails-ish'' to me... dwh On Sep 30, 11:35 am, "Robby Russell" <ro...-/Lcn8Y7Ot69QmPsQ1CNsNQ@public.gmane.org> wrote:> On Tue, Sep 30, 2008 at 7:54 AM, Phillip Koebbe > > <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > I''ve been vacillating between using the :locals hash and instance > > variables when passing data to partials. Is there a valid reason to use > > one over the other? What could be considered a best practice in the > > Rails community? I did some googling but didn''t turn anything up. > > As a general rule of thumb, you''ll want to be conservative when it > comes to scoping your variables. In my opinion, it''s best to use > locals and not rely on an instance variable. > > Cheers, > > Robby > > -- > Robby Russell > Chief Evangelist, Partner > > PLANET ARGON, LLC > design // development // hosting > > http://www.planetargon.com/http://www.robbyonrails.com/ > aim: planetargon > > +1 503 445 2457 > +1 877 55 ARGON [toll free] > +1 815 642 4068 [fax]--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---