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:

<%= lnk_to gtype.name, :controller => β€˜articletypes’,
:action => β€˜edit’, :id => gtype.id %>
34:
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? ? β€˜β€™: β€˜β€™) +
options_for_select(gtype.articletypesizes.collect{|g| [g.size.name,
g.id]}, t) %>
37:
38:
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:inmethod_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:inrender_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:inrender’
/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:inbenchmark’
/usr/lib/ruby/1.8/benchmark.rb:293:in measure' /usr/lib/ruby/1.8/benchmark.rb:307:inrealtime’
/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:inrender_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:inrender_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:inrender_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:inrender_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:inmeasure’
/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:inperform_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:inperform_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:inperform_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:inprocess_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:inprocess’
/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:inprocess_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:ineach_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:inprocess!’
/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:inmethod_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:incompile_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:inrender_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:inrender_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:inmeasure’
/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:inbenchmark’
/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:inrender_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:inrender_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:inrender_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:inmeasure’
/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:inperform_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:inperform_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:inperform_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:inprocess_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:inprocess’
/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:inprocess_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:ineach_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:inprocess!’
/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


user: !ruby/object:User
attributes:
language: Netherlands
deleted_on:
id: β€œ2”
password: 3cbb9f188f1fb46186075e39237709810d198383
login: Albert
userprofile_id: β€œ1”
userprofile: !ruby/object:Userprofile
attributes:
name: Administrator
id: β€œ1”
deleted_on:
comment: Administrator access
userprivileges:
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ140”
subject: clientgroups
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ141”
subject: clients
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ142”
subject: clientdepartments
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ143”
subject: articleusers
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ144”
subject: articles
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ145”
subject: distributors
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ146”
subject: scanlocations
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ147”
subject: contracts
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ148”
subject: invoices
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ149”
subject: loadingadvice
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ150”
subject: logs
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ151”
subject: suppliers
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ152”
subject: cleaningmethodgroups
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ153”
subject: cleaningmethods
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ154”
subject: finishingmethods
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ155”
subject: sizes
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ156”
subject: colors
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ157”
subject: qualities
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ158”
subject: articlegroups
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ159”
subject: articletypes
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ160”
subject: articledamages
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ161”
subject: clienttypes
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ162”
subject: notifications
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ163”
subject: notificationreasons
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ164”
subject: notificationactions
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ165”
subject: userprofiles
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
- !ruby/object:Userprivilege
attributes:
new: β€œ1”
delete: β€œ1”
list: β€œ1”
edit: β€œ1”
id: β€œ166”
subject: users
deleted_on:
show: β€œ1”
userprofile_id: β€œ1”
articleusers_sort:
:order: asc
:key: surname
flash: !map:ActionController::Flash::FlashHash {}

Response
Headers: {β€œcookie”=>[], β€œContent-Type”=>β€œtext/html; charset=utf-8”,
β€œCache-Control”=>β€œno-cache”}

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

<%= lnk_to gtype.name, :controller => 'articletypes', :action => 'edit', :id => gtype.id %> <% t = @articletypesizes.select{|n| n.articletype_id == gtype.id}.first.articletypesize_id.to_i rescue nil %> <%= select_tag "sizes[#{gtype.id}]", (t.nil? ? '': '') + options_for_select(gtype.articletypesizes.collect{|g| [g.size.name, g.id]}, t) %> <% 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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs