jeudi 14 juin 2018

Better way than if foo.blank?

I am building a basic app that will retrieve a customers data and show it on screen, however some of the fields will be null and so I get a lot of undefined method 'registration_number' for nil:NilClass errors

Is there a better way to to deal with these other than lots of if statements

if  @customer.registration_number.blank?
Do something
else
@customer.registration_number
end

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire