I like to add a different way json data is rendered in Rails.
The problem is is that i don't want all the field names for each row, just a array with data for each column, moreover it would be nice to setup some type of filter so you can select which columns you want in the JSON output
At the moment i have in a controller:
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @person }
end
And i would like to do something like:
format.json { render :json2 => @person }
So that in this specific action of a controller, the JSON data is formatted differently (:json2). I was looking at:
ActionController.add_renderer :json2 do |json, options|
But i can't wrap my head around this. Were do i start? I do want it to run it in the same way as the 'default' json renderer. So no separate index.json2.erb files in each view. Even better if i can add some extra fields to the array like:
format.json { render :json2 => @person, :table = 'xyz', :columns = ['a', 'b'] }
I did read Yehuda Katz but i still can't figure it out.