Tôi đã cố gắng theo dõi Active Record Nested Attributes Guide, mà không thành công nhiều.Rails accept_nested_attributes_for Lỗi, hãy giúp tôi phát hiện ra nó
tôi có các mô hình sau:
class Contact < ActiveRecord::Base
has_many :telephones
accepts_nested_attributes_for :telephones
end
class Telephone < ActiveRecord::Base
belongs_to :contact
end
Khi cố gắng để tạo ra một số liên lạc:
contact = {
:name => "John",
:telephones => [
{:telephone => '787445741'},
{:telephone => '478589658'}
]
}
Contact.create(contact)
tôi nhận được lỗi sau: ActiveRecord::AssociationTypeMismatch: Telephone(#80827590) expected, got Hash(#72886250)
Ông có thể vui lòng giúp tôi nhận ra sự lỗi? Có mã nào tôi nên đưa vào trong contact_controller.rb
không?