Forum: Ruby on Rails checking for existence of object in views

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Mike B. (Guest)
on 2006-03-07 02:07
(Received via mailing list)
In my views I often find an error caused by trying to display a
property of a non-existent object.

Is there is a simpler way to avoid this than to append an 'if'
conditional at the end
of each statement where the 'belongs_to' object does not exist?

<% for person in @people %>
     <td><%=h person.address.streetname if person.address %></td>
<% end %>


This topic is locked and can not be replied to.