0
trennen Ich möchte folgende Daten mit Jbuilder machen.
Wie kann ich jbuilder trennen?Wie kann ich Vorlagen durch Daten in Jbuilder
data: [{
type: "top"
logo: "logo.png"
title: "title"
},{
type: "nav"
background: "bg.png"
content: "<div> Welcome </div>"
},{
type: "footer"
content: "Copyright: xx"
}
]
Ich habe es so, aber konnte nicht ausgeführt
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
Wie kann ich das Problem lösen?