Rails 2.3.4 ActiveRecord association problem

Upgraded our app from Rails 2.2.2 to 2.3.4, and I’m now encountering
an error when adding a child to a parent.

Top of the stack:

wrong number of arguments (1 for 0)
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/
associations/has_many_association.rb:61:in save' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/ associations/has_many_association.rb:61:ininsert_record’
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/
associations/association_collection.rb:119:in <<' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/ associations/association_collection.rb:433:inadd_record_to_target_with_callbacks’

My code (in snippets):

class Trip < ActiveRecord::Base
has_many :activity_reservations
end

class ActivityReservation < ActiveRecord::Base
belongs_to :trip
end

trip.activity_reservations << ActivityReservation.new

The has_many_associations code referenced:

    def insert_record(record, force = false, validate = true)
      set_belongs_to_association_for(record)
      force ? record.save! : record.save(validate)
    end

The ActiveRecord save method:

  def save
    create_or_update
  end

The comments for the save method indicate that it can take an optional
perform_validations method, and the Validations module defines (with
alias_method_chain :save, :validation).

So, finally my question: what is going on here? ActiveRecord is
calling a save method passing an arg, but the save method in
ActiveRecord isn’t defined to take a boolean. I’m guessing that
something with the Validations and alias_method_chain is supposed to
handle this, but in the way I’m doing things in my code, its not
working.

(ActiveRecord 2.2.2, which we were on previously, just called
ActiveRecord.save - not attempting to pass a boolean)

Any help or pointers would be greatly appreciated.

Paul Christmann

We had a similar problem. In our case, we had written a custom save
method for one of our models, which took no parameters. Once we rewrote
it to accept an optional perform_validations parameter, all was good.

The ActiveRecord::Base API documentation changed in Rails 2.1 to include
an optional parameter, i.e. save(perform_validation = true). The
underlying method does not yet accept this parameter, but unless you go
out of your way to disable the validations framework, it’s replaced by
save_with_validation(perform_validation = true) and thus complies with
the API.