Tuesday, 27 August 2013

Rails complex if

Rails complex if

I wonder what the beautiful way to output this in Rails.
order.items.min.user.email
I want to show the value of email, the only thing I know is order is not
nil, however items and user might be nil.
The only way I see is
if !order.items.empty?
if !order.items.min.user.nil?
if !order.items.min.user.email.nil?
order.items.min.user.email
end
end
end
It looks like not the best way, do you know the better way?

No comments:

Post a Comment