0
Я хочу сделать следующие данные с jbuilder.
Как я могу изолировать 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
Как я могу решить эту проблему?