Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails handling .Erb with Nils

keeps giving me grief when profile is nil... what can i do?

like image 239
Chris Avatar asked Apr 25 '10 19:04

Chris


2 Answers

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.

like image 139
Damien Wilson Avatar answered Oct 21 '22 18:10

Damien Wilson


This should work, too

<%= image_tag(this.profile.expiring_url(180)) rescue "no image!" %>
like image 42
maček Avatar answered Oct 21 '22 16:10

maček