Skip to content

Instantly share code, notes, and snippets.

@xuncheng
Created January 4, 2014 14:18
Show Gist options
  • Save xuncheng/8255814 to your computer and use it in GitHub Desktop.
Save xuncheng/8255814 to your computer and use it in GitHub Desktop.
Generates the Gravatar for given user.
# Returns the Gravatar (http://gravatar.com) for the given user.
def gravatar_for(user, options = {size: 40})
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
size = options[:size]
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
image_tag(gravatar_url, alt: user.full_name)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment