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("S ELECT .....")
In view:
<% if @attending_ip != nil%>
<% @attending_ip.each do |u| %>
...
...
<%if u.admit_date != nil%><%= u.admit_date.to_formatted_ s(:my_form at_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,
I am wondering if there is smart/elegant ways of checking nil object.
I have this in controller:
@attending_ip = AttendingIp.find_by_sql("S
In view:
<% if @attending_ip != nil%>
<% @attending_ip.each do |u| %>
...
...
<%if u.admit_date != nil%><%= u.admit_date.to_formatted_
...
...
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER