【发布时间】:2013-05-12 17:07:26
【问题描述】:
我正在尝试通过将以下内容传递给 create 来创建画廊模型及其 has_many 关联。
[
{
"title":"Some Titler",
"description":"",
"date":"18-3-2012",
"photographs":[
{
"title": "Some Title",
"camera": "Canon 600D"
},
{
"title": "Some Other Title",
"camera": "Canon 600D"
}
]
}
]
如果没有嵌套的 photographs 数组,它可以正常工作,但是使用它,我会收到错误:
Photograph(#70242279271180) expected, got Hash(#70242248401160)
语法有什么问题?
class Gallery < ActiveRecord::Base
attr_accessible :date, :description, :published, :title
has_many :photographs
accepts_nested_attributes_for :photographs
end
【问题讨论】:
标签: ruby-on-rails rest model nested-attributes nested-resources