Last active
December 12, 2022 23:39
-
-
Save ryenski/368e43e243d34252e4f138565c9e041a to your computer and use it in GitHub Desktop.
gravatar_helper.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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