I have this simple construction:
<% if !@user.address.empty? && !@user.zip.empty? %>
<%= @user.address+', '+@user.zip%>
<% end %>
If are address and zip filled out, it’s ok. But if not, on localhost is not printed out the middle line. That’s ok as well.
But on Heroku, if address and zip are not filled out, I get the error
ActionView::Template::Error (undefined method `empty?' for nil:NilClass):
How is that possible?
Note: address and zip have the datatype varchar(255).
EDIT: I forgot to add an important note: @user is NEVER nil.
Try using
present?Under the surface
present?is just!blank?which will test for empty strings as well as fornil,{}and[].In your case: