【问题标题】:Rails - Creating a model and its nested resourcesRails - 创建模型及其嵌套资源
【发布时间】: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


    【解决方案1】:

    改变

     "photographs":[]
    

     "photographs_attributes":[]
    

    【讨论】:

    • 该死的。那是我以前的事。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多