jbuilder
code:show.json.jbuilder
json.extract! @book, :id, :name, :price
json.publisher do
json.name @book.publisher.name
json.address @book.publisher.address
end
unless @book.high_price?
json.low_price true
end
code:output
{
"id":1,
"name":"Book 1",
"price":1000,
"name_with_id":"1 - Book 1",
"publisher":
{
"name":"GIhyo inc.",
"address":"Ichigaya"
},
"low_price":true
}