# Update\_attributes

**URL:** <https://www.ruby-forum.com/t/update-attributes/95037>\
**Category:** Rails\
**Created:** [May 19, 2006, 8:46pm UTC](https://www.ruby-forum.com/t/update-attributes/95037 "2006-05-19T20:46:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterbe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bc79bd/32.png) [@peterbe](https://www.ruby-forum.com/u/peterbe)\
**Post date:** [May 19, 2006, 8:46pm UTC](https://www.ruby-forum.com/t/update-attributes/95037/1 "2006-05-19T20:46:43Z")

</div>

My application is so far mostly built from scaffold.  
When I edit an existing record (I’ve turned off validation) the update  
method is called. I get this error:

NoMethodError in /#update  
You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occured while evaluating nil.+

I get the same error when I call update\_attributes from the console  
Any ideas?

The stack trace is below.

Thanks,  
Peter

/web/server/pkgs/ruby-1.8.4/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active\_record/locking.rb:37:in  
`update_without_callbacks' /web/server/pkgs/ruby-1.8.4/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/callbacks.rb:274:in`update\_without\_timestamps’  
/web/server/pkgs/ruby-1.8.4/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active\_record/timestamp.rb:39:in  
`update' /web/server/pkgs/ruby-1.8.4/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:1718:in`create\_or\_update\_without\_callbacks’  
/web/server/pkgs/ruby-1.8.4/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active\_record/callbacks.rb:249:in  
`create_or_update' /web/server/pkgs/ruby-1.8.4/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:1392:in`save\_without\_validation’  
/web/server/pkgs/ruby-1.8.4/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active\_record/validations.rb:724:in  
`save_without_transactions' /web/server/pkgs/ruby-1.8.4/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/transactions.rb:126:in`save’  
/web/server/pkgs/ruby-1.8.4/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active\_record/connection\_adapters/abstract/database\_statements.rb:51:in  
`transaction' /web/server/pkgs/ruby-1.8.4/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/transactions.rb:91:in`transaction’  
/web/server/pkgs/ruby-1.8.4/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active\_record/transactions.rb:118:in  
`transaction' /web/server/pkgs/ruby-1.8.4/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/transactions.rb:126:in`save’  
/web/server/pkgs/ruby-1.8.4/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active\_record/base.rb:1439:in  
`update_attributes' #{RAILS_ROOT}/app/controllers/admin/library_controller.rb:39:in`update’

---

<div class="post-metadata">

**Author:** ![peterbe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bc79bd/32.png) [@peterbe](https://www.ruby-forum.com/u/peterbe)\
**Post date:** [May 19, 2006, 9:05pm UTC](https://www.ruby-forum.com/t/update-attributes/95037/2 "2006-05-19T21:05:19Z")

</div>

Hi Peter,

Peter Ensch wrote:

> My application is so far mostly built from scaffold.

That ‘mostly’ thing will getcha from time to time 😉

It will help to see your code. Could you post the code from the update  
method? Also, the view / form that’s calling the method?

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![peterbe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bc79bd/32.png) [@peterbe](https://www.ruby-forum.com/u/peterbe)\
**Post date:** [May 19, 2006, 9:54pm UTC](https://www.ruby-forum.com/t/update-attributes/95037/3 "2006-05-19T21:54:21Z")

</div>

Bill W. wrote:

> It will help to see your code. Could you post the code from the update  
> method? Also, the view / form that’s calling the method?

Sure. Here’s the update method (from  
app/controllers/admin/library\_controller.rb):

##############################  
class Admin::LibraryController \< ApplicationController  
…

def update  
@library = Library.find(params[:id])  
if @library.update\_attributes(params[:library])  
flash[:notice] = ‘Library was successfully updated.’  
redirect\_to :action =\> ‘show’, :id =\> @library  
else  
render :action =\> ‘edit’  
end  
end  
##############################

Here’s the rendered form from (  
app/views/admin/library/edit.rhtml  
app/views/admin/library/\_form.rhtml  
app/views/layouts/admin/library.rhtml):

##############################

 Admin::Library: edit 

# Editing library

Name

Macro case

Naming convention

…  
much more here…

[Show](https://www.ruby-forum.com/admin/library/show/121) |  
[Back](https://www.ruby-forum.com/admin/library/list)

##############################
