I am using rocket pants to render my JSON API.
I’m trying to change the way it renders the JSON by overriding as_json in my model, but somehow, it seems not to change anything in the rocket pants response.
in my controller:
class Api::V1::ProjectsController < RocketPants::Base
...
def show
expose Project.find(params[:id])
end
...
end
And in my model:
class Project < ActiveRecord::Base
...
def as_json(options = {})
{"this" => "is not working!"}
end
...
end
What am I missing?
I’ve figured out how to do that. The way rocket pants work is by looking at the
serializable_hashmethod. Overriding it results in a change in the response.Edit:
The solution I got to:
In the model where I need to add some attributes: simply override the attributes method:
In the controller that needs to expose the API I’ve created a new Model class (this is only needed in order to keep different API versions), and overridden the serializable_hash method: