2020-01-07 17:29:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Avatarable
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
|
|
|
|
included do
|
|
|
|
has_one_attached :avatar
|
|
|
|
end
|
|
|
|
|
|
|
|
def avatar_url
|
2020-11-13 14:26:30 +00:00
|
|
|
return url_for(avatar.representation(resize: '250x250')) if avatar.attached? && avatar.representable?
|
|
|
|
|
|
|
|
if [User, Contact].include?(self.class) && email.present?
|
|
|
|
hash = Digest::MD5.hexdigest(email)
|
|
|
|
return "https://www.gravatar.com/avatar/#{hash}?d=404"
|
2020-01-07 17:29:17 +00:00
|
|
|
end
|
2020-11-13 14:26:30 +00:00
|
|
|
|
|
|
|
''
|
2020-01-07 17:29:17 +00:00
|
|
|
end
|
|
|
|
end
|