Forum: Ruby on Rails Need help with ArgumentError during save()

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
William L. (Guest)
on 2007-02-10 03:09
    I've been getting an error all afternoon and haven't been able to
figure it out; any help would be wonder full.


class Project < ActiveRecord::Base
  belongs_to :job
  belongs_to :thumbnail, :class_name => 'Image', :foreign_key =>
  has_and_belongs_to_many :services

class Thumbnail < Image
  has_one :project


class Admin::ProjectsController < ApplicationController

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

    #if there's an id then do an update otherwise it's a new project so
do a save
   if params[:id]
     @s1 = if @project.thumbnail
     @s2 = @project.update_attributes( params[:project] )    # this is
the line which fails
     @saved = ( @s1 == false || @s2 == false ) ? false : true
     @saved =

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

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)

Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/controllers/admin/projects_controller.rb:48:in `save'

Parameters: {"commit"=>"Save", "project"=>{"job_id"=>"4", "title"=>"test
- no errors", "client"=>"big client", "description"=>"descriptoin is
good"}, "id"=>"32", "service_ids"=>["462", "483"],

Show session dump


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
Chris T (Guest)
on 2007-02-10 11:42
(Received via mailing list)
Which is line 48
William L. (Guest)
on 2007-02-10 22:24
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.
William L. (Guest)
on 2007-02-10 22:43
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.
This topic is locked and can not be replied to.