I have a text value in my AR model which defaults to null. I want to check the value for whether it is either not nil or not the empty string.
<% if !item.public_notes.empty? && !item.public_notes.nil? %>
<%=item.public_notes %>
<% end %>
here’s the error:
ActionView::Template::Error (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.empty?):
If set to null, the attribute comes back as nil and errors out on the first case. It seems like I shouldn’t have to nest these. What is the proper way to check in the view layer? Is the error pointing to issue mentioned above?
thx
I would use
unless, and the rails helperblank?(which checks if it’s nil? or empty?)