【发布时间】:2017-06-08 13:27:34
【问题描述】:
我想用 jbuilder 制作以下数据。
如何让 jbuilder 分离?
data: [{
type: "top"
logo: "logo.png"
title: "title"
},{
type: "nav"
background: "bg.png"
content: "<div> Welcome </div>"
},{
type: "footer"
content: "Copyright: xx"
}
]
我是这样做的,但无法运行
data.jbuilder
json.set! :result do
json.array! data do |item|
case item.type
when 'top'
json.partial! '_top', item: item
when 'nav'
json.partial! '_nav', item: item
when 'footer'
json.partial! '_footer', item: item
else
return nil
end
end
_top.jbuilder
json.logo item.logo
json.title item.title
_nav.jbuilder
json.background item.background
json.content item.content
_footer.jbuilder
json.content item.content
我该如何解决这个问题?
【问题讨论】:
标签: ruby sinatra padrino jbuilder