Specifying attributes of a Rails object passed into a JSON object
render :json => @user
will call to_json
on the @user object. And the to_json
method will use the as_json
method to do its work. So you can easily override the as_json
to pass only what you want to the clients. Like in the following:
def as_json options={}
{
attr1: attr1,
attr2: attr2
}
end