Jbuilder Partials Merge 而不是 Nest

Jbuilder Partials Merge Instead of Nest

我正在尝试获得如下所示的 json 响应:

{
    id: 3,
    title: "Magic",
    desc: "A bag of coolness!"
    type: {
        id: 14,
        title: "Dust"
    }
}

我得到的是:

{
    id:14,
    title:"Dust",
    desc:"A bag of coolness!"
    type: null
}

正在使用的三个 jbuilder 文件如下:

_item.json.jbuilder

json.(item, :id, :title, :desc)
json.type json.partial! item.type

show.json.jbuilder

json.partial! @item

_type.json.jbuilder

json.(type, :id, :title)

为什么jbuilder合并类型和项目而不是嵌套类型?我该如何防止这种情况?

要嵌套部分,下面的代码可以工作:

json.type do
    json.partial! item.type
end