mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-08-14 02:50:42 +09:00
b065b40a34
and add test coverage for (un)supported file types. The avatar and logo variants move into the models and return nil for content types that are no longer variable, so the controllers fall back to the initials avatar and stock logo icon instead of raising `ActiveStorage::InvariableError`.
24 lines
460 B
Ruby
24 lines
460 B
Ruby
module User::Avatar
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
has_one_attached :avatar do |attachable|
|
|
attachable.variant :square, resize_to_limit: [ 512, 512 ], format: :webp
|
|
end
|
|
end
|
|
|
|
class_methods do
|
|
def from_avatar_token(sid)
|
|
find_signed!(sid, purpose: :avatar)
|
|
end
|
|
end
|
|
|
|
def avatar_token
|
|
signed_id(purpose: :avatar)
|
|
end
|
|
|
|
def avatar_variant
|
|
avatar.variant(:square).processed if avatar.variable?
|
|
end
|
|
end
|