I have a rails4 app, where one of the controllers have a variable @data
in my controller as follows:
@data = {
2013 => {sal: 1000, exp: 400},
2014 => {sal: 1170, exp: 460},
2015 => {sal: 660, exp: 1120},
2016 => {sal: 1030, exp: 540}
}
I have associated json jbuilder file where I want to use this to render json in this structure
[
['Year', 'Sales', 'Expenses'],
['2013', 1000, 400],
['2014', 1170, 460],
['2015', 660, 1120],
['2016', 1030, 540]
]
I was looking at https://github.com/rails/jbuilder, but could not figure out as how to achieve my goal.
This did not help..
json.array! @data do |d|
???
end
Any help will be appreciated!