Let us say I have a model Post which belongs to a User. To convert to json, I do something like this
@reply.to_json(:include => {:user => {:only =>
You can do this by overriding serializable_hash in your model, like so:
class Reply < ActiveRecord::Base
def serializable_hash(options={})
options = {
:include => {:user => {:only => [:email, :id]},
:only => [:title, :id]
}.update(options)
super(options)
end
end
This will affect all serializable methods, including serializable_hash, to_json, and to_xml.