Forum: Ruby on Rails update_attributes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Peter E. (Guest)
on 2006-05-19 22:46
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 <module>/<controller>#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'
Bill W. (Guest)
on 2006-05-19 23:05
(Received via mailing list)
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
Peter E. (Guest)
on 2006-05-19 23:54
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):

##############################
<html>
<head>
  <title>Admin::Library: edit</title>
  <link href="/stylesheets/scaffold.css?1147799338" media="screen"
rel="Stylesheet" type="text/css" />
</head>
<body>

<p style="color: green"></p>

<h1>Editing library</h1>


<form action="/admin/library/update/121" method="post">

<!--[form:library]-->

<p><label for="library_name">Name</label><br/>
<input id="library_name" name="library[name]" size="30" type="text"
value="SR60LX" /></p>

<p><label for="library_macro_case">Macro case</label><br/>
<input id="library_macro_case" name="library[macro_case]" size="30"
type="text" value="lower" /></p>

<p><label for="library_naming_convention">Naming convention</label><br/>
<input id="library_naming_convention" name="library[naming_convention]"
size="30" type="text" value="standard" /></p>

...
much more here...

<!--[eoform:library]-->

  <input name="commit" type="submit" value="Edit" />
</form>

<a href="/admin/library/show/121">Show</a> |
<a href="/admin/library/list">Back</a>


</body>
</html>
##############################
This topic is locked and can not be replied to.