Checking for existence of object in views


#1

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 %>

<%=h person.address.streetname if person.address %> <% end %>

thanks,

Mike