6
我一直在試圖關注Active Record Nested Attributes Guide,沒有太大的成功。rails accept_nested_attributes_for錯誤,請幫我看看吧
我有以下型號:
class Contact < ActiveRecord::Base
has_many :telephones
accepts_nested_attributes_for :telephones
end
class Telephone < ActiveRecord::Base
belongs_to :contact
end
當試圖創建聯繫人:
contact = {
:name => "John",
:telephones => [
{:telephone => '787445741'},
{:telephone => '478589658'}
]
}
Contact.create(contact)
我收到以下錯誤: ActiveRecord::AssociationTypeMismatch: Telephone(#80827590) expected, got Hash(#72886250)
能否請你幫我當場錯誤? 我應該在contact_controller.rb
中包含哪些代碼?