The standard mechanism I return JSON in a Rails controller is with:
respond_to do |format|
format.html
format.json { render json: @cars }
end
Is there a way to modify the @cars
JSON? In particular I simply want to add 4 extra fields in there.
UPDATE: Sorry, I should've explained a little more. @cars
contains a list of Car
objects. I want to add 4 fields to each Car
object in the JSON. This is unique to a particular controller, so I don't want to make an as_json
method as that would affect other JSONs of this class.