(Sometimes) Undefined Variables in Partials

I’ve noticed that under some (unknown) circumstances local variables to
partials are undefined and under other (equally mysterious)
circumstances they are defined but nil. Here’s an example of what I’m
talking about.

<%= render :partial => ‘my_partial’, :locals => { :var1 = > ‘foo’ } %>

The partial (note, var2 was not passed above):

<% if var2 -%>
Variable number 2 was passed!
<% else -%>
Variable number 2 was not passed!
<% end -%>

Sometimes this will throw an exception complaining about the variable
being not defined. Other times, the variable will be defined and its
value is nil. I’m wondering if this has something to do with garbage

I’ve noticed that if the same partial is called from another page and
the variables ARE passed in, later on on a different page where the
variables are NOT passed in, the partial treats them as nil. I haven’t
seen this behave consistently, however. Which made me think there were
external forces at work, hence my GC theory (although I admit I don’t
know much about GC in Ruby, so I am reaching with this theory).

Has anyone else experienced this? Is there something obvious I’m
missing? Thanks in advance.

  • Jason