0
我是rails中的新角色。我有兩個類的故事和場景。故事has_may場景和場景belong_to stories.When我稱之爲 '/stories/1/scenes.json',那麼我想這個輸出在rails中生成嵌套對象json響應4
「故事」:[{
"name": "akbar and bilber",
"description": "some description",
"story_type": "simple",
"state": "active",
"scenes":{
"id":"1"
"name": "Akber's introduction",
"description":"Akber is king"
},
{
"id":"2"
"name": "bilber's introduction",
"description":"bilber's is consultant of akber"
},
"created_at": "2013-09-22T16:32:41.050Z",
"updated_at": "2013-09-22T16:32:41.050Z",
}]
這裏是模型:
class Story < ActiveRecord::Base
has_many :scene
end
class Scene < ActiveRecord::Base
belongs_to :story
end
我需要寫在這些控制器和show.json.jbulder文件中。
它提供了錯誤「無法找到故事沒有ID」。如何訪問故事的id場景控制器?請從strach告訴我。 –
我修復了這個問題。謝謝 –
我應該怎樣處理故事/ 1/scene/1.json才能從故事中獲取單個場景? –