Forum: Rails deployment "undefined local variable or method" in view, for "if var"

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jared S. (Guest)
on 2008-11-24 08:09
Hey, this feels like a dumb question, but I feel like this should be
working.

I have a partial, and sometimes when I render it I'm passing in a
variable via :locals called "invisible", because sometimes I want it to
start out as "display:none" then use js to make it appear. If I don't
pass it that variable, I want it to display normally.

So I have this line in my view:
<% if invisible %>
  style="display:none;"
<% end %>

And I'm getting the "undefined local variable or method `invisible'"
error. I would think that "invisible" would be nil, and evaluate to
false, as it does in ruby code. Is that not the case with .html.erb
files?

I tried this, and get the same result:

<% if !invisible.nil? %>
  style="display:none;"
<% end %>

Can anyone shine some light on this quirk? Is there a place that
describes how erb works differently than ruby code?

Thanks in advance!
This topic is locked and can not be replied to.