Skip to content

Instantly share code, notes, and snippets.

@8parth
Last active October 20, 2016 17:06
Show Gist options
  • Save 8parth/2086e70fe4431e961fb0ea2c87103488 to your computer and use it in GitHub Desktop.
Save 8parth/2086e70fe4431e961fb0ea2c87103488 to your computer and use it in GitHub Desktop.
old approach of overriding as_json
# override as_json method of User class
def as_json(options={})
h = {
name: self.name,
picture: self.picture.url(:medium),
age: self.age
}
h
end
# put helper methods, such as creating full name from given first_name and last_name attribute of user
def name
self.first_name +" " +self.last_name
end
# example response, note that timestamps, authentication token and password digest fields are not present
# user: {
# name: "some name",
# picture: "url",
# age: 20
# }
# most important: calling render json: @user returns this response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment