我有以下型号:
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=
任何帮助?