Hi,
<%= image_tag this.profile.expiring_url(180) %>
keeps giving me grief when profile is nil... what can i do?
Thanks in advance!
Hi,
<%= image_tag this.profile.expiring_url(180) %>
keeps giving me grief when profile is nil... what can i do?
Thanks in advance!
Always check if a variable is nil
before using it in a view.
<% image_tag this.profile.expiring_url(180) unless this.profile.nil? %>
I'm sure there's a more elegant solution to the problem, but that should get you started.
First you'd need to decide what you want to do when there is no profile. Do you want to display a default image? No image at all?
Assuming you wanted to display a default image, you could add a method to your helper:
def expiration_url_for( profile )
(profile && profile.expiring_url(180)) || default_url
end
and then call that helper method in your view:
<%=image_tag expiration_url_for( this.profile )%>
This should work, too
<%= image_tag(this.profile.expiring_url(180)) rescue "no image!" %>