Chris Roos
2006-Sep-18 13:07 UTC
Partials retaining reference to previously defined locals
Hi, Problem occurs where partial is rendered with explicit locals. Subsequent rendering of that partial without those locals, or with different locals, retains access to the previous keys (NOT values). I''ve tracked the problem (if it is a problem) to ActionView::Base.compile_template_source and the use of @@template_args. The reason I question whether it is a genuine problem is because maybe this is known and accepted for performance reasons. Although, I''m not sure it is particularly problematic, it can cause unexpected behviour. Example of unexpected behaviour.. * I have two actions, both of which render(:partial => ''my_partial''). The first renders with some locals that my_partial depends upon. * I visit the first action (that sets locals) and see the partial correctly. * I visit the second action (that doesn''t set locals) and see the partial correctly. * Unexpected - It should break. * Restarting the webserver (or running a separate test that doesn''t first call the action with the locals) confirms that the second action/partial combo is broken. I''m incredibly unfamiliar with the templating stuff and so have restrained from submitting some tests, although I do have an example of showing that access to locals (note, access not the values) are persisted. Any suggestions on what should be happening? Cheers, Chris --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core -~----------~----~----~----~------~----~------~--~---
Andy Watts
2008-Jan-30 03:18 UTC
Re: Partials retaining reference to previously defined local
I''ve noticed this behavior in consecutive calls to the same partial. 1. render :partial => ''blah'', :locals => {:somevar => true} 2. render :partial => ''blah'' In the second call to the partial, "defined?(somevar)" will return true...even tho it wasn''t in the locals passed in the render.. I''d like to have optional locals on some of my partials. The current behavior requires me to always pass the local :somevar. Does this strike anyone else as an issue? cheers Andy -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
If this is happening then it is an issue in an unexpected behaviour way. On Jan 30, 8:18 am, Andy Watts <ruby-forum-incom...@andreas-s.net> wrote:> I''ve noticed this behavior in consecutive calls to the same partial. > > 1. render :partial => ''blah'', :locals => {:somevar => true} > 2. render :partial => ''blah'' > > In the second call to the partial, "defined?(somevar)" will return > true...even tho it wasn''t in the locals passed in the render.. > > I''d like to have optional locals on some of my partials. > The current behavior requires me to always pass the local :somevar. > > Does this strike anyone else as an issue? > > cheers > Andy > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Stefan Kaes
2008-Feb-02 09:10 UTC
Re: Partials retaining reference to previously defined local
You cannot test whether a certain key (:somevar) was present in the locals hash passed to render using defined?(:somevar), due to the way template compilation works in Rails. But you can use the following pattern instead: local_assigns.include?(:somevar) -- stefan kaes On Jan 30, 2008 4:18 AM, Andy Watts <ruby-forum-incoming@andreas-s.net> wrote:> > I''ve noticed this behavior in consecutive calls to the same partial. > > 1. render :partial => ''blah'', :locals => {:somevar => true} > 2. render :partial => ''blah'' > > In the second call to the partial, "defined?(somevar)" will return > true...even tho it wasn''t in the locals passed in the render.. > > I''d like to have optional locals on some of my partials. > The current behavior requires me to always pass the local :somevar. > > Does this strike anyone else as an issue? > > cheers > Andy > -- > Posted via http://www.ruby-forum.com/. > > > >-- -- For rails performance tuning, see: http://railsexpress.de/blog Subscription: http://railsexpress.de/blog/xml/rss20/feed.xml --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---