Skip to content

Instantly share code, notes, and snippets.

@ryenski
Last active December 12, 2022 23:39
Show Gist options
  • Save ryenski/368e43e243d34252e4f138565c9e041a to your computer and use it in GitHub Desktop.
Save ryenski/368e43e243d34252e4f138565c9e041a to your computer and use it in GitHub Desktop.
gravatar_helper.rb
# frozen_string_literal: true
module GravatarHelper
def gravatar_image_tag(email, attrs = {})
attrs = {
class: 'h-10 w-10 rounded-full'
}.update(attrs)
image_tag gravatar_url(email), attrs
end
def gravatar_url(email, size = 200)
if email.blank?
asset_pack_path('media/images/gravatar.png')
else
gravatar_id = Digest::MD5.hexdigest(email.try(:downcase))
"https://www.gravatar.com/avatar/#{gravatar_id}.png?d=mm&s=#{size}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment