Skip to content

Instantly share code, notes, and snippets.

@telamon
Created May 24, 2011 17:37
Show Gist options
  • Save telamon/989218 to your computer and use it in GitHub Desktop.
Save telamon/989218 to your computer and use it in GitHub Desktop.
Simple Gravatar helper for Rails
module GravatarHelper
def gravatar_tag(email,*args)
opts = args.extract_options!
opts[:class]||=""
opts[:class]+=" gravatar"
size = opts.delete(:size) || 80
require 'digest/md5'
default=""
if opts[:default]
require 'cgi'
default= "&d=#{CGI::escape(opts.delete(:default))}"
end
hash = Digest::MD5.hexdigest(email.downcase)
img= image_tag "http://www.gravatar.com/avatar/#{hash}?size=#{size}#{default}", opts
if opts[:profile]
opts.delete(:profile)
link_to img,"http://www.gravatar.com/#{hash}",opts
else
img
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment