NIL trouble since upgrading Rails

Hello,

For a distribution system at work we created a webinterface in Rails. Last week we upgraded Rails from 1.0.0 to 1.1.6. I know, we should have done it earlier... :wink: Anyway. Since then, on most pages we get errors about objects returning NIL. But before the upgrade, everything worked perfect. I can't find anything wrong in the code, but thats probably just me being a noob.

Has anyone got any great tips?

Regards,

Albert

NoMethodError in Articleusers#edit

Showing app/views/articleusers/_list_departments_and_sizes.rhtml where line #36 raised:

You have a nil object when you didn't expect it! The error occured while evaluating nil.name

Extracted source (around line #36):

33: <td><%= lnk_to gtype.name, :controller => 'articletypes', :action => 'edit', :id => gtype.id %></td> 34: <td> 35: <% t = @articletypesizes.select{|n| n.articletype_id == gtype.id}.first.articletypesize_id.to_i rescue nil %> 36: <%= select_tag "sizes[#{gtype.id}]", (t.nil? ? '<option value="" selected="selected"></option>': '') + options_for_select(gtype.articletypesizes.collect{|g| [g.size.name, g.id]}, t) %> 37: </td> 38: </tr> 39: <% end %>

Trace of template inclusion: /app/views/articleusers/edit.rhtml

RAILS_ROOT: /home/technico/projects/technico/public/../config/.. Application Trace | Framework Trace | Full Trace

#{RAILS_ROOT}/app/views/articleusers/_list_departments_and_sizes.rhtml:36:in `_run_rhtml_articleusers__list_departments_and_sizes' #{RAILS_ROOT}/app/views/articleusers/_list_departments_and_sizes.rhtml:36:in `_run_rhtml_articleusers__list_departments_and_sizes' #{RAILS_ROOT}/app/views/articleusers/_list_departments_and_sizes.rhtml:31:in `_run_rhtml_articleusers__list_departments_and_sizes' #{RAILS_ROOT}/app/views/articleusers/edit.rhtml:71:in `_run_rhtml_articleusers_edit'

/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/association_proxy.rb:110:in `method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_association.rb:90:in `method_missing' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:316:in `compile_and_render_template' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:292:in `render_template' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:251:in `render_file' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:266:in `render' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/partials.rb:59:in `render_partial' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:29:in `benchmark' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/lib/ruby/1.8/benchmark.rb:307:in `realtime' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:29:in `benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/partials.rb:58:in `render_partial' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:316:in `compile_and_render_template' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:292:in `render_template' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:251:in `render_file' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:726:in `render_file' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:648:in `render_with_no_layout' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/layout.rb:245:in `render_without_benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in `render' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in `render' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:942:in `perform_action_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:368:in `perform_action_without_benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/rescue.rb:82:in `perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in `process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in `process_without_session_management_support' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:in `process' /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in `dispatch' /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:150:in `process_request' /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:54:in `process!' /usr/lib/ruby/1.8/fcgi.rb:600:in `each_cgi' /usr/lib/ruby/1.8/fcgi.rb:597:in `each_cgi' /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:53:in `process!' /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:23:in `process!' /home/technico/projects/technico/public/dispatch.fcgi:24

#{RAILS_ROOT}/app/views/articleusers/_list_departments_and_sizes.rhtml:36:in `_run_rhtml_articleusers__list_departments_and_sizes' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/association_proxy.rb:110:in `method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_association.rb:90:in `method_missing' #{RAILS_ROOT}/app/views/articleusers/_list_departments_and_sizes.rhtml:36:in `_run_rhtml_articleusers__list_departments_and_sizes' #{RAILS_ROOT}/app/views/articleusers/_list_departments_and_sizes.rhtml:31:in `_run_rhtml_articleusers__list_departments_and_sizes' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:316:in `compile_and_render_template' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:292:in `render_template' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:251:in `render_file' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:266:in `render' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/partials.rb:59:in `render_partial' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:29:in `benchmark' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/lib/ruby/1.8/benchmark.rb:307:in `realtime' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:29:in `benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/partials.rb:58:in `render_partial' #{RAILS_ROOT}/app/views/articleusers/edit.rhtml:71:in `_run_rhtml_articleusers_edit' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:316:in `compile_and_render_template' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:292:in `render_template' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:251:in `render_file' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:726:in `render_file' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:648:in `render_with_no_layout' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/layout.rb:245:in `render_without_benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in `render' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in `render' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:942:in `perform_action_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:368:in `perform_action_without_benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/rescue.rb:82:in `perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in `process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in `process_without_session_management_support' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:in `process' /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in `dispatch' /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:150:in `process_request' /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:54:in `process!' /usr/lib/ruby/1.8/fcgi.rb:600:in `each_cgi' /usr/lib/ruby/1.8/fcgi.rb:597:in `each_cgi' /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:53:in `process!' /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:23:in `process!' /home/technico/projects/technico/public/dispatch.fcgi:24

Request

Parameters: {"id"=>"181"}

Show session dump

Perhaps I should have included some code in my first post instead of a full error page. This is the code in the _view that worked perfectly with Rails 1.0.0 and not with 1.2.6:

<% @articleuser.clientdepartments.collect{|cd|cd.articletypes.reject{|gt| gt.maximum == '0'}}.flatten.uniq.each do |gtype| %>   <tr>     <td><%= lnk_to gtype.name, :controller => 'articletypes', :action => 'edit', :id => gtype.id %></td>     <td>       <% t = @articletypesizes.select{|n| n.articletype_id == gtype.id}.first.articletypesize_id.to_i rescue nil %>       <%= select_tag "sizes[#{gtype.id}]", (t.nil? ? '<option value="" selected="selected"></option>': '') + options_for_select(gtype.articletypesizes.collect{|g| [g.size.name, g.id]}, t) %>     </td>   </tr> <% end %>

(paste to notepad for clearity) g.size.name returns NIL, but it shouldn't...

Thanks,

Albert

Ofcoarse I meant Rails 1.1.6 instead of 1.2.6.

Any hints or ideas?