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'%>

<td ><a href="<%=h @attachment.attachment.url %>" target="_blank"

Attachment</a>&nbsp;&nbsp;&nbsp;&nbsp; <a

href='#'onmouseover="Tip('<%=h @attachment.attachment %>',LEFT, true, CLOSEBTN,false,FADEOUT,1000, SHADOW,true, STICKY,false, WIDTH,300 )">File Name</a></td>       <% else %>         <%= puts 'is not empty'%>

  <td class="searchResultLineItem1">No attachment</td>       <% 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

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.

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     <a

href=‘#‘onmouseover="Tip(’<%=h @attachment.attachment %>’,LEFT, true, CLOSEBTN,false,FADEOUT,1000, SHADOW,true, STICKY,false, WIDTH,300 )">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

Posted via http://www.ruby-forum.com/.

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'%>

<td ><a href="<%=h @attachment.attachment.url %>" target="_blank"

Attachment</a>&nbsp;&nbsp;&nbsp;&nbsp; <a

href='#'onmouseover="Tip('<%=h @attachment.attachment %>',LEFT, true, CLOSEBTN,false,FADEOUT,1000, SHADOW,true, STICKY,false, WIDTH,300 )">File Name</a></td>       <% else %>         <%= puts 'is not empty'%>

  <td class="searchResultLineItem1">No attachment</td>       <% 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

Hi    I have already checked as u said              if @attachment

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