Undefined method 'insert_record' on ActiveRecord save

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:incallback’
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:incallback’
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:ineach’
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:increate_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:increate’
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:increate_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:insave_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:intransaction’
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:intransaction’
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:inrollback_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:insave’
app/controllers/batches_controller.rb:156:in create' -e:2:inload’
-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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs