Skip to content

Instantly share code, notes, and snippets.

@istvanp
Created September 14, 2011 08:27
Show Gist options
  • Save istvanp/1216104 to your computer and use it in GitHub Desktop.
Save istvanp/1216104 to your computer and use it in GitHub Desktop.
{
city: "Montreal",
first_name: "Istvan",
id: 1,
last_name: "Pusztai",
state: "Quebec",
avatar_url: "https://secure.gravatar.com/avatar/44c6f8371be4ee1612256855a3e35d12.png?s=48&d=http%3A%2F%2Frobohash.org%2F44c6f8371be4ee1612256855a3e35d12.png%3Fsize%3D48x48%26bgset%3Dany"
}
def as_json(options = {})
super only: [
:id,
:first_name,
:last_name,
:full_name,
:city,
:state
], methods: [
:avatar_url
]
end
def avatar_url(size = 48)
hash = Digest::MD5.hexdigest(self.email.downcase)
default = ERB::Util.u "http://robohash.org/#{hash}.png?size=#{size}x#{size}&bgset=any"
"https://secure.gravatar.com/avatar/#{hash}.png?s=#{size}&d=#{default}"
end
def show
@user = current_user
respond_to do | format |
format.html
format.json { render json: @user }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment