# Undefined method 'insert\_record' on ActiveRecord save

**URL:** <https://www.ruby-forum.com/t/undefined-method-insert-record-on-activerecord-save/133085>\
**Category:** Rails\
**Created:** [March 27, 2008, 4:29pm UTC](https://www.ruby-forum.com/t/undefined-method-insert-record-on-activerecord-save/133085 "2008-03-27T16:29:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [March 27, 2008, 4:29pm UTC](https://www.ruby-forum.com/t/undefined-method-insert-record-on-activerecord-save/133085/1 "2008-03-27T16:29:28Z")

</div>

Each time I try to save a particular model class (in this case a Batch)  
in my application, I receive the following error:

undefined method `insert\_record’ for #Array:0x4c8fc7c

It seems that ActiveRecord is somehow getting a hold of an array and  
doesn’t know how to save it. Can anyone shed some light on what could be  
causing this?

I am using the userstamp plugin, and removed it to eliminate the  
possibility that it was the culprit, but I receive the same error (minus  
the pertinent line in the trace).

Stack trace:  
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/callbacks.rb:319:in  
`send' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:319:in`callback’  
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/callbacks.rb:319:in  
`each' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:319:in`callback’  
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/callbacks.rb:309:in  
`callback' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:304:in`each’  
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/callbacks.rb:304:in  
`callback' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:227:in`create\_without\_timestamps’  
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/timestamp.rb:29:in  
`create_without_user' vendor/plugins/userstamp/lib/userstamp.rb:36:in`create’  
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/base.rb:2238:in  
`create_or_update_without_callbacks' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/callbacks.rb:213:in`create\_or\_update’  
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/base.rb:1972:in  
`save_without_validation' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/validations.rb:934:in`save\_without\_transactions’  
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/transactions.rb:108:in  
`save' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in`transaction’  
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/transactions.rb:80:in  
`transaction' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:100:in`transaction’  
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/transactions.rb:108:in  
`save' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:120:in`rollback\_active\_record\_state!’  
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/transactions.rb:108:in  
`save' app/models/batch.rb:99:in`save’  
app/controllers/batches\_controller.rb:156:in `create' -e:2:in`load’  
-e:2

# in batch\_controller.rb

#====================================  
if @batch.save # this is line 156

# do some other stuff

end

# batch.rb

#======================  
class Batch \< ActiveRecord::Base  
has\_many :items  
has\_many :batch\_field\_values  
belongs\_to :created\_by, :class\_name =\> “User”, :foreign\_key =\>  
“created\_by”  
belongs\_to :updated\_by, :class\_name =\> “User”, :foreign\_key =\>  
“updated\_by”  
belongs\_to :location  
belongs\_to :product  
alias\_attribute :user, :created\_by

# other methods omitted

def save  
if super # this is line 99  
@items.each do |item|  
item.save  
self.items \<\< item  
end  
end  
end

# more stuff omitted

end

# item.rb

#=====================  
class Item \< ActiveRecord::Base  
belongs\_to :created\_by, :class\_name =\> “User”, :foreign\_key =\>  
“created\_by”  
belongs\_to :updated\_by, :class\_name =\> “User”, :foreign\_key =\>  
“updated\_by”  
belongs\_to :location  
belongs\_to :batch  
belongs\_to :product  
attr\_protected :user\_id, :ip\_address, :location\_id, :product\_id,  
:created\_at, :updated\_at, :created\_by, :updated\_by  
alias\_attribute :user, :created\_by  
end

# batch\_field\_values.rb

#=======================  
class BatchFieldValue \< ActiveRecord::Base  
belongs\_to :item\_batch\_field  
belongs\_to :batch  
end

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [March 1, 2009, 2:39pm UTC](https://www.ruby-forum.com/t/undefined-method-insert-record-on-activerecord-save/133085/2 "2009-03-01T14:39:36Z")

</div>

I’ve got the same problem “Undefined method ‘insert\_record’”. Could you  
solve that problem?
