ruby on rails - Nil object when didn't expect it -


legacy ruby on rails 2.3 project here. getting following error:

you have nil object when didn't expect it! might have expected instance of activerecord::base. error occurred while evaluating nil.[] 

extracted source (around line #122):

119: <%= link_to 'printable', { :action => 'print', :id => @incident.id }, { :target => '_blank', :class => "button" } %> 120: <% if isviewable?(@incident) %> 121:  122:   <%= link_to "pictures (#{@incident.pictures.count})", incident_pictures_path(@incident), :class => "button" %> 123:   <%= link_to "suspects (#{@incident.suspects.count})", incident_suspects_path(@incident), :class => "button" %> 124:   <%= link_to "notes (#{@incident.notes.count})", incident_notes_path(@incident), :class => "button"%> 125:   <%= link_to "cars (#{@incident.cars.count})", incident_cars_path(@incident), :class => "button" %> 

any ideas anyone? thanks.

edit: removing line 122 fixes exception, might need show picture if record has one, can't take out functionality.

edit 2: there line in exception page under application trace:

/usr/local/rvm/gems/ruby-1.8.7-p371/gems/paperclip-2.3.0/lib/paperclip.rb:303:in `validates_attachment_content_type' 

could error paperclip plugin?

119: <%= link_to 'printable', { :action => 'print', :id => @incident.id }, { :target => '_blank', :class => "button" } %>     <% if @incident.present?%>       #### need check null object. ###### 120: <% if isviewable?(@incident) %> 121: 122:   <%= link_to "pictures (#{@incident.pictures.count})", incident_pictures_path(@incident), :class => "button" %> 123:   <%= link_to "suspects (#{@incident.suspects.count})", incident_suspects_path(@incident), :class => "button" %> 124:   <%= link_to "notes (#{@incident.notes.count})", incident_notes_path(@incident), :class => "button"%> 125:   <%= link_to "cars (#{@incident.cars.count})", incident_cars_path(@incident), :class => "button" %> 

you need check null object, work fine hopefully.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -