# NIL trouble since upgrading Rails

**URL:** <https://www.ruby-forum.com/t/nil-trouble-since-upgrading-rails/73396>\
**Category:** Rails\
**Created:** [October 24, 2006, 11:29am UTC](https://www.ruby-forum.com/t/nil-trouble-since-upgrading-rails/73396 "2006-10-24T11:29:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bitmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b9e5f3/32.png) [@Bitmaster](https://www.ruby-forum.com/u/Bitmaster)\
**Post date:** [October 24, 2006, 11:29am UTC](https://www.ruby-forum.com/t/nil-trouble-since-upgrading-rails/73396/1 "2006-10-24T11:29:50Z")

</div>

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… 😉  
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: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

* * *

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  
🔑 surname  
flash: !map:ActionController::Flash::FlashHash {}

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

---

<div class="post-metadata">

**Author:** ![Bitmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b9e5f3/32.png) [@Bitmaster](https://www.ruby-forum.com/u/Bitmaster)\
**Post date:** [October 27, 2006, 12:09pm UTC](https://www.ruby-forum.com/t/nil-trouble-since-upgrading-rails/73396/2 "2006-10-27T12:09:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Bitmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b9e5f3/32.png) [@Bitmaster](https://www.ruby-forum.com/u/Bitmaster)\
**Post date:** [October 27, 2006, 12:17pm UTC](https://www.ruby-forum.com/t/nil-trouble-since-upgrading-rails/73396/3 "2006-10-27T12:17:22Z")

</div>

Ofcoarse I meant Rails 1.1.6 instead of 1.2.6.

---

<div class="post-metadata">

**Author:** ![Bitmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b9e5f3/32.png) [@Bitmaster](https://www.ruby-forum.com/u/Bitmaster)\
**Post date:** [November 7, 2006, 10:52am UTC](https://www.ruby-forum.com/t/nil-trouble-since-upgrading-rails/73396/4 "2006-11-07T10:52:21Z")

</div>

Any hints or ideas?
