【发布时间】:2015-03-12 14:48:46
【问题描述】:
我正在尝试使用 jBuilder 创建一个 json 文件,并且我可以使关系“belongs_to”起作用,但我不能为“has_one”做什么。
所以我有一个解决方案模型:
class Solution
belongs_to :user
has_one :world
end
我用它来创建json文件,我可以从solution.user.name中得到名字,但是我怎样才能得到世界的信息呢?
json.array! (@solutions) do |json, solution|
json.id solution.id
json.name solution.user.name
json.world solution.world
end
提前感谢您的帮助!
【问题讨论】: