Looking to have two tests on a variable, that might not be defined in a rails view.
<% if defined(:var) && var.present? %>
<%= var.value %>
<% end %>
However, this is throwing a undefined local variable or method
error when var
is not defined. I assumed ruby/rails would short circuit the first expression and not try to evaluate the second, similar to python
>>> a = False
>>> a and b
False
>>> b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'b' is not defined
Any reason why short circuit is preceeding to the second evaluation?