Update_attributes


#1

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:inupdate_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:increate_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:insave_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:insave’
/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:intransaction’
/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:insave’
/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:inupdate’


#2

Hi Peter,

Peter Ensch wrote:

My application is so far mostly built from scaffold.

That ‘mostly’ thing will getcha from time to time :wink:

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


#3

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

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