# Need help with ArgumentError during save()

**URL:** <https://www.ruby-forum.com/t/need-help-with-argumenterror-during-save/85108>\
**Category:** Rails\
**Created:** [February 10, 2007, 2:09am UTC](https://www.ruby-forum.com/t/need-help-with-argumenterror-during-save/85108 "2007-02-10T02:09:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wlefevre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/71e660/32.png) [@wlefevre](https://www.ruby-forum.com/u/wlefevre)\
**Post date:** [February 10, 2007, 2:09am UTC](https://www.ruby-forum.com/t/need-help-with-argumenterror-during-save/85108/1 "2007-02-10T02:09:46Z")

</div>

Greetings,  
I’ve been getting an error all afternoon and haven’t been able to  
figure it out; any help would be wonder full.

Models-----

class Project \< ActiveRecord::Base  
belongs\_to :job  
belongs\_to :thumbnail, :class\_name =\> ‘Image’, :foreign\_key =\>  
‘image\_id’  
has\_and\_belongs\_to\_many :services  
end

class Thumbnail \< Image  
has\_one :project  
end

Controller------

class Admin::ProjectsController \< ApplicationController

def save  
.  
.  
. # thumbnail image has been uploaded, created, and added to  
@project.thumbnail

```
#if there's an id then do an update otherwise it's a new project so

```

do a save  
if params[:id]  
@s1 = @project.thumbnail.save if @project.thumbnail  
@s2 = @project.update\_attributes( params[:project] ) # this is  
the line which fails  
@saved = ( @s1 == false || @s2 == false ) ? false : true  
else  
@saved = @project.save  
end

if @saved # decide what to render or where to redirect, etc.  
.  
.  
.  
end  
end

I only run into problems when no thumbnail has been previously saved and  
the thumbnail I’m trying to save is invalid (ie. fails to save). If a  
thumbnail has already been saved then uploading a new, invalid thumbnail  
is handled perfectly. It also doesn’t matter if the Project is being  
saved for the first time or updated.

Here’s the full error I’m getting:

ArgumentError in Admin/projectsController#save

wrong number of arguments (1 for 0)  
RAILS\_ROOT:  
/Users/william/Projects/rails/lizarddesign/public/…/config/…

Application Trace | Framework Trace | Full Trace  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/callbacks.rb:349:in  
`save' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/callbacks.rb:349:in`callback’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/callbacks.rb:346:in  
`callback' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/callbacks.rb:341:in`each’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/callbacks.rb:341:in  
`callback' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/callbacks.rb:252:in`create\_or\_update’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/base.rb:1392:in  
`save_without_validation' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/validations.rb:736:in`save\_without\_transactions’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/transactions.rb:126:in  
`save' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/database_statements.rb:51:in`transaction’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/transactions.rb:91:in  
`transaction' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/transactions.rb:118:in`transaction’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/transactions.rb:126:in  
`save' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1439:in`update\_attributes’  
#{RAILS\_ROOT}/app/controllers/admin/projects\_controller.rb:48:in `save’  
Request

Parameters: {“commit”=\>“Save”, “project”=\>{“job\_id”=\>“4”, “title”=\>"test

- no errors", “client”=\>“big client”, “description”=\>“descriptoin is  
good”}, “id”=\>“32”, “service\_ids”=\>[“462”, “483”],  
“image”=\>{“thumbnail”=\>#StringIO:0x26bf6b4}}

Show session dump

Response

Headers: {“cookie”=\>[], “Cache-Control”=\>“no-cache”}

Lastly it doesn’t crash till after the after\_validation callback.

I’m stymied. Any insight would be great.

Thanks William

---

<div class="post-metadata">

**Author:** ![wlefevre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/71e660/32.png) [@wlefevre](https://www.ruby-forum.com/u/wlefevre)\
**Post date:** [February 10, 2007, 10:42am UTC](https://www.ruby-forum.com/t/need-help-with-argumenterror-during-save/85108/2 "2007-02-10T10:42:54Z")

</div>

Which is line 48  
(#{RAILS\_ROOT}/app/controllers/admin/projects\_controller.rb:48)?

---

<div class="post-metadata">

**Author:** ![wlefevre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/71e660/32.png) [@wlefevre](https://www.ruby-forum.com/u/wlefevre)\
**Post date:** [February 10, 2007, 9:24pm UTC](https://www.ruby-forum.com/t/need-help-with-argumenterror-during-save/85108/3 "2007-02-10T21:24:59Z")

</div>

Chris T wrote:

> Which is line 48  
> (#{RAILS\_ROOT}/app/controllers/admin/projects\_controller.rb:48)?

line 48 is:  
@s2 = @project.update\_attributes( params[:project] )

I get the error for both Project#update\_attributes and Project#save when  
the referenced (belongs\_to) Thumbnail fails validation and does not  
save. Also this only happens if there has never been an associated  
Thumbnail. Once one is successfully associated it’s no longer a problem.

---

<div class="post-metadata">

**Author:** ![wlefevre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/71e660/32.png) [@wlefevre](https://www.ruby-forum.com/u/wlefevre)\
**Post date:** [February 10, 2007, 9:43pm UTC](https://www.ruby-forum.com/t/need-help-with-argumenterror-during-save/85108/4 "2007-02-10T21:43:14Z")

</div>

William L. wrote:

> Greetings,  
> I’ve been getting an error all afternoon and haven’t been able to  
> figure it out; any help would be wonder full.

Whew. I figured it out a solution but I don’t feel 100% why I was  
getting this error. If anyone has any insight I’d still love to hear it.

The solution was simple, I added:

```
  validates_associated :thumbnail

```

to my Project model and all is good.
