I am currently using the following:
20: <p>Status: <%= @contact.try(:status) unless @contact.nil? || @contac
t.status.nil?%></p>
However, I still get the following error:
ActionView::TemplateError (undefined method `status' for nil:NilClass) on line #
20 of app/views/contacts/show.html.erb:
Is there a better way to be checking?
This seems to be a common problem -- it works fine in dev but I am not finding it in production....
Use the Rails utility method try
<%= @contact.try(:status) %>
Maybe
<%= @contact.status unless @contact %>
or
<%= @contact && @contact.status %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With