Skip to content

Instantly share code, notes, and snippets.

@damian
Created December 13, 2010 11:01
Show Gist options
  • Save damian/738893 to your computer and use it in GitHub Desktop.
Save damian/738893 to your computer and use it in GitHub Desktop.
Gravatar with options
require 'digest/md5'
def gravatar(user, options = {})
email_address = user.email.downcase
hash = Digest::MD5.hexdigest(email_address)
image_src = "http://www.gravatar.com/avatar/#{hash}"
unless options.empty?
query_string = options.map {|key, value| "#{key}=#{value}"}
image_src << "?" << query_string.join("&")
end
image_tag(image_src)
end
<%= gravatar(current_user, { :size => 50, :default => 'identicon' }) %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment