我正在尝试使用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提前感谢您的帮助!
发布于 2015-03-14 00:08:57
因此,我必须将模型中的关系更改为:
belongs_to:world然后它就起作用了。
https://stackoverflow.com/questions/29012939
复制相似问题