I'd like to submit JSON's response as follows, but it's clogged up.
Could you give me some advice?
Currently
[["book", 10], ["pen", 100]]
Goals
[
{
category:book
amount —10
},
{
category:pen
amount: 100
}
]
Current State Source
controller
def index
@category_history=CategoryHistory.all.group(:category).sum(:amount)
end
json.builder
json.array!@category_history
How about this one?
#json.builder
json.array!@category_history do|ch|
json.category ch[0]
json.amountch[1]
end
As for jbuilder, there are many samples written on README, so if you get lost, you can look at it
https://github.com/rails/jbuilder
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
582 PHP ssh2_scp_send fails to send files as intended
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
578 Understanding How to Configure Google API Key
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.