未定义的方法`add_record_to_target_with_callbacks for Array` - 升级到Ruby 2.1.0时

时间:2014-05-13 07:07:39

标签: ruby-on-rails ruby rails-activerecord

我有以下型号:

class Person < ActiveRecord::Base
    has_many :children, :dependent => :destory
    accepts_nested_attributes_for :children, :allow_destroy => true
end

分配时:

per.children_attributes = { '0' => {'name' => 'ben' } }

我收到以下异常: undefined method add_record_to_target_with_callbacks for Array

stacktrace:

/home/nitzany/.rvm/gems/ruby-2.1.0/gems/activerecord-3.0.20/lib/active_record/associations/association_proxy.rb:159:in send /home/nitzany/.rvm/gems/ruby-2.1.0/gems/activerecord-3.0.20/lib/active_record/nested_attributes.rb:376:in 'block in assign_nested_attributes_for_collections_association /home/nitzany/.rvm/gems/ruby-2.1.0/gems/activerecord-3.0.20/lib/active_record/nested_attributes.rb:367:in 'each' /home/nitzany/.rvm/gems/ruby-2.1.0/gems/activerecord-3.0.20/lib/active_record/nested_attributes.rb:367: in 'assign_nested_attributes_for_collection_association" /home/nitzany/.rvm/gems/ruby-2.1.0/gems/activerecord-3.0.20/lib/active_record/nested_attributes.rb:254:in children_attributers=

  • 降级到ruby 1.9.2问题已解决
  • 当捕获异常并再次运行相同的代码行时,问题已解决

任何帮助?

0 个答案:

没有答案