Martin Lübcke
2008-Mar-23 17:46 UTC
Locals do not appear in partial unless collection is explici
Maybe I''m misunderstanding something but it appears as if <%= render :partial => @items, @locals => { :this => ''that'' } %> does not give the local variable this but this one does: <%= render :partial => ''items/item'', :collection => @items, @locals => { :this => ''that'' } %> Shouldn''t they mean the same thing? I''m running rails 2.0.2 Martin -- 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 -~----------~----~----~----~------~----~------~--~---
Mark Bush
2008-Mar-23 18:09 UTC
Re: Locals do not appear in partial unless collection is exp
Martin Lübcke wrote:> Maybe I''m misunderstanding something but it appears as if > <%= render :partial => @items, @locals => { :this => ''that'' } %>Don''t you want :locals => { ... ? -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Martin Lübcke
2008-Mar-23 18:16 UTC
Re: Locals do not appear in partial unless collection is exp
Mark Bush wrote:> Martin Lübcke wrote: >> Maybe I''m misunderstanding something but it appears as if >> <%= render :partial => @items, @locals => { :this => ''that'' } %> > > Don''t you want :locals => { ... > ?Yes, that is both what I want and what I mean. It should be :locals in both lines, the @ was just a typo. Martin -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Mar-23 18:58 UTC
Re: Locals do not appear in partial unless collection is explici
On 23 Mar 2008, at 17:46, Martin Lübcke wrote:> > Maybe I''m misunderstanding something but it appears as if > <%= render :partial => @items, @locals => { :this => ''that'' } %> > does not give the local variable this but this one does: > <%= render :partial => ''items/item'', :collection => @items, @locals > => { > :this => ''that'' } %>Is @locals just a typo? Should be :locals. Fred> > Shouldn''t they mean the same thing? > I''m running rails 2.0.2 > > Martin > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Mar-23 18:58 UTC
Re: Locals do not appear in partial unless collection is explici
On 23 Mar 2008, at 18:58, Frederick Cheung wrote:> > On 23 Mar 2008, at 17:46, Martin Lübcke wrote: > >> >> Maybe I''m misunderstanding something but it appears as if >> <%= render :partial => @items, @locals => { :this => ''that'' } %> >> does not give the local variable this but this one does: >> <%= render :partial => ''items/item'', :collection => @items, @locals >> => { >> :this => ''that'' } %> > > Is @locals just a typo? Should be :locals. >Oops, ignore me, being a bit slow today. Fred> Fred >> >> Shouldn''t they mean the same thing? >> I''m running rails 2.0.2 >> >> Martin >> -- >> 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Bush
2008-Mar-23 19:35 UTC
Re: Locals do not appear in partial unless collection is exp
Martin Lübcke wrote:>>> <%= render :partial => @items, @locals => { :this => ''that'' } %> >> > Yes, that is both what I want and what I mean. It should be :locals in > both lines, the @ was just a typo.ok :-) Looking at the code for render_partial (abbreviated): def render_partial(partial_path, object_assigns = nil, local_assigns = nil) case partial_path when String, Symbol, NilClass : local_assigns = local_assigns ? local_assigns.clone : {} : render("#{path}/_#{partial_name}", local_assigns) : when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::Associations::HasManyThroughAssociation : render_partial_collection(path, collection, nil, object_assigns.value) : So, if you pass an array or an association collection (such as @items above) as the value of the :partial key, then local_assigns is *not* passed through. Unless I''m reading this all wrong. I have not looked to see if this is expected behaviour or a bug... -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Bush
2008-Mar-23 19:45 UTC
Re: Locals do not appear in partial unless collection is exp
Mark Bush wrote:> def render_partial(partial_path, object_assigns = nil, local_assigns = > nil) > : > render_partial_collection(path, collection, nil, > object_assigns.value) > :To complete the picture here, the definition of render goes: def render(options = {}, old_local_assigns = {}, &block) #:nodoc: : elsif options.is_a?(Hash) : elsif options[:partial] && options[:collection] render_partial_collection(options[:partial], options[:collection], options[:spacer_template], options[:locals]) elsif options[:partial] render_partial(options[:partial], ActionView::Base::ObjectWrapper.new(options[:object]), options[:locals]) So yes, things work differently for partials if a collection is supplied. Note that options[:locals] is supplied to #render_partial but the argument in my previous post shows why this is not passed through to #render_partial_collection, but it is if options[:collection] is defined. -- 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 -~----------~----~----~----~------~----~------~--~---