Rails - Always have to check exists, and then value?
Posted
by
Jason B
on Stack Overflow
See other posts from Stack Overflow
or by Jason B
Published on 2012-11-05T16:13:59Z
Indexed on
2012/11/05
17:00 UTC
Read the original article
Hit count: 127
ruby-on-rails
|ruby-on-rails-3
I am checking to see if a value in a related table exists quite often in my view, in this case, expenses have approvals. If they have not been submitted, then there is no record of them in the approvals table.
I am ending up with some really awkward code
<% if !expense_item.expense_approval || expense_item.expense_approval.approval_status == 0 %>
Is there a way to do an if statement on a value, without having to check if it exists first? Or some default way to set it nil?
© Stack Overflow or respective owner