0

我試圖通過將以下內容傳遞給create來創建Gallery模型及其has_many關聯。Rails - 創建模型及其嵌套資源

[ 
    { 
    "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 

回答

1

變化

"photographs":[] 

"photographs_attributes":[] 
+0

該死。這是我以前的事。非常感謝。 – Undistraction 2013-05-12 18:25:35