Skip to content

Instantly share code, notes, and snippets.

@delba
Last active December 17, 2015 03:09
Show Gist options
  • Select an option

  • Save delba/5541314 to your computer and use it in GitHub Desktop.

Select an option

Save delba/5541314 to your computer and use it in GitHub Desktop.
Gravatar
module Gravatar
BASE_URL = "http://www.gravatar.com/avatar".freeze
def gravatar_url(options = {})
"#{BASE_URL}/#{email_hash}?#{options.to_query}"
end
private
def email_hash
Digest::MD5.hexdigest(email)
end
end
class User < ActiveRecord::Base
include Gravatar
end
module UsersHelper
def gravatar_for(user, size: "80", alt: user.username)
image_tag user.gravatar_url(size: size), size: size, alt: alt
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment