Ruby on rails Jbuilder分区合并而不是嵌套

Ruby on rails Jbuilder分区合并而不是嵌套,ruby-on-rails,ruby,json,jbuilder,Ruby On Rails,Ruby,Json,Jbuilder,我试图得到一个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文件如下:

我试图得到一个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
json.partial! @item
json.(type, :id, :title)
show.json.jbuilder

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

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

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

要嵌套分部,以下代码将起作用:

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

要嵌套分部,以下代码将起作用:

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