Link to home
Start Free TrialLog in
Avatar of dkim18
dkim18

asked on

checking nil object

hi,

I am wondering if there is smart/elegant ways of checking nil object.

I have this in controller:

 @attending_ip = AttendingIp.find_by_sql("SELECT .....")

In view:

<% if @attending_ip != nil%>
<% @attending_ip.each do |u|  %>
...
...

<%if u.admit_date != nil%><%= u.admit_date.to_formatted_s(:my_format_0)  %><%end%>

...
...

I am checking  whether u.admit_date is nil otherwise, it throws error message since admit_date can be null. So, do I always have to check for all the columns? Are there better ways of doing this?

thx,
ASKER CERTIFIED SOLUTION
Avatar of peh803
peh803
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dkim18
dkim18

ASKER

Ok, that is good enough. thx!