# Rails 2.3.4 ActiveRecord association problem

**URL:** <https://www.ruby-forum.com/t/rails-2-3-4-activerecord-association-problem/175255>\
**Category:** Rails\
**Created:** [September 10, 2009, 9:28am UTC](https://www.ruby-forum.com/t/rails-2-3-4-activerecord-association-problem/175255 "2009-09-10T09:28:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Christmann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b19c9b/32.png) [@Paul\_Christmann](https://www.ruby-forum.com/u/Paul_Christmann)\
**Post date:** [September 10, 2009, 9:28am UTC](https://www.ruby-forum.com/t/rails-2-3-4-activerecord-association-problem/175255/1 "2009-09-10T09:28:32Z")

</div>

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:in`insert\_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:in`add\_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

---

<div class="post-metadata">

**Author:** ![Paul\_Christmann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b19c9b/32.png) [@Paul\_Christmann](https://www.ruby-forum.com/u/Paul_Christmann)\
**Post date:** [November 24, 2009, 10:56am UTC](https://www.ruby-forum.com/t/rails-2-3-4-activerecord-association-problem/175255/2 "2009-11-24T10:56:22Z")

</div>

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.
