ruby-on-rails – Rails accepted_nested_attributes_for错误,请
发布时间:2020-12-16 23:03:50 所属栏目:百科 来源:网络整理
导读:我一直在努力追随 Active Record Nested Attributes Guide,没有太大的成功. 我有以下型号: class Contact ActiveRecord::Base has_many :telephones accepts_nested_attributes_for :telephonesendclass Telephone ActiveRecord::Base belongs_to :contacte
我一直在努力追随
Active Record Nested Attributes Guide,没有太大的成功.
我有以下型号: 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) 我收到以下错误: 你能帮我看看错误吗? 解决方法
我使用以下代码:
params = { :contact => { :name => 'Joe',:permanentcomment => "No Comment",:telephones_attributes => [ {:telephone => '787445741'},{:telephone => '478589658'} ] }} Contact.create(params[:contact]) 我将错误的参数传递给Contact.create控制器…… (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |