Module: Polivalente::GravatarHelper

Defined in:
app/helpers/polivalente/gravatar_helper.rb

Instance Method Summary collapse

Instance Method Details

#user_avatar(user) ⇒ Object



11
12
13
# File 'app/helpers/polivalente/gravatar_helper.rb', line 11

def user_avatar(user)
  user.photo.attached? ? user.photo : user_gravatar(user.email, size: 40)
end

#user_gravatar(email, options = {}) ⇒ Object



4
5
6
7
8
9
# File 'app/helpers/polivalente/gravatar_helper.rb', line 4

def user_gravatar(email, options = {})
  return unless URI::MailTo::EMAIL_REGEXP.match?(email)
  email_md5 = Digest::MD5.hexdigest(email.downcase.strip)
  query_params = url_params(options)
  @gravatar_image_url = "https://www.gravatar.com/avatar/#{email_md5}#{query_params}"
end