The error occurred while evaluating nil

Hi
I ahve a code like
<%@attachment=ServiceDeskActivityAttachment.find_by_service_desk_activity_id(@sd_activities[loop_index].id)
%>
<% if !@attachment.blank? %>
<%= puts ‘is empty’%>

Attachment     File Name <% else %> <%= puts 'is not empty'%> No attachment <% end %>

But I always get the error
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.url

But I am achecking <% if !@attachment.blank? %> …Is it not the right
way?If <% if !@attachment.blank? %> is true how the controll enters in
the if case above?Should it enter the else case only?Please help

Thanks in advance
Sijo

Sijo Kg wrote:

Hi
I ahve a code like
<%@attachment=ServiceDeskActivityAttachment.find_by_service_desk_activity_id(@sd_activities[loop_index].id)
%>
<% if !@attachment.blank? %>
<%= puts ‘is empty’%>

Attachment     File Name <% else %> <%= puts 'is not empty'%> No attachment <% end %>

But I always get the error
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.url

But I am achecking <% if !@attachment.blank? %> …Is it not the right
way?If <% if !@attachment.blank? %> is true how the controll enters in
the if case above?Should it enter the else case only?Please help

Thanks in advance
Sijo

Hi Sijo
nil is entirely diferent from blank.your page showing error as nil
so try the following
if @attachment
--------------
end

the above condition checks for nil.
and further if your facing like these problem use script/console and
give the query check wat value is coming and procede further.

Hi
I have already checked as u said
if @attachment
--------------
end
But getting the same error

Sijo

2008/7/30, Sijo Kg [email protected]:

You’re checking @attachment.blank, but you use
@attachment.attachment.url. It looks you occasionally duplicated
“attachment”. Or if you have a method “attachment” under @attachment,
you should check that for nil also (@attachment.attachment.blank?).

LoKi.

The attachment method on attachment is returning nil, not the
@attachment
variable itself.