"undefined local variable or method" in view, for "if var"

Hey, this feels like a dumb question, but I feel like this should be

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 %>
<% 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

I tried this, and get the same result:

<% if !invisible.nil? %>
<% 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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs