Skip to content

Instantly share code, notes, and snippets.

@ninetwentyfour
Created May 30, 2011 02:45
Show Gist options
  • Save ninetwentyfour/998390 to your computer and use it in GitHub Desktop.
Save ninetwentyfour/998390 to your computer and use it in GitHub Desktop.
Rails Helper that will return a url for a gravatar
module GravatarHelper
def gravatar_url_for(email, options = {})
options = { :size => '200', :default => 'retro', :rating => 'pg'}.merge(options)
size = options[:size]
rating = options[:rating]
default = options[:default]
# create the md5 hash
hash = Digest::MD5.hexdigest(email)
# compile URL which can be used in <img src="RIGHT_HERE"...
image_src = "http://www.gravatar.com/avatar/#{hash}?s=#{size}r=#{rating}&d=#{default}"
return image_src
end
end
@ninetwentyfour
Copy link
Author

Usage:

<%= image_tag(gravatar_url_for(email, {:options => 'here'})) %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment