Rails accepted_nested_attributes_for错误,请帮我发现它
我一直在尝试遵循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)
我收到以下错误: ActiveRecord::AssociationTypeMismatch: Telephone(#80827590) expected, got Hash(#72886250)
你能帮我看看错误吗? 我应该在contact_controller.rb
包含任何代码吗?
我使用以下代码:
params = { :contact => { :name => 'Joe', :permanentcomment => "No Comment", :telephones_attributes => [ {:telephone => '787445741'}, {:telephone => '478589658'} ] }} Contact.create(params[:contact])
我将错误的参数传递给Contact.create
控制器……
- 如何获取ActiveRecordvalidation中配置的最大长度?
- ActiveRecord :: AdapterNotSpecified数据库配置未指定适配器
- 在Rails应用程序中的查询运行时更改表名
- 是否有Ruby数据库迁移gem,它可以帮助您将内容从旧结构移动到新结构?
- 当我尝试做rake db:migrate时,我收到一个错误:ActiveRecord :: NODatabaseError角色“ubuntu”不存在
- 使用rails嵌套模型来创建*外部对象并同时*编辑*现有的嵌套对象?
- 如何将BIG SQL文件导入rails数据库?
- 将模型动态连接到正在运行的应用程序中的数据库?
- Rails的Active Record可以处理SQL聚合查询吗?