Use variant declarations instead of custom methods

This commit is contained in:
Râu Cao 2023-09-06 12:38:47 +02:00
parent def44618ef
commit 64d09cfb7f
Signed by: raucao
GPG Key ID: 15E65F399D084BA9
2 changed files with 6 additions and 10 deletions

View File

@ -9,7 +9,11 @@ class User < ApplicationRecord
# File attachments
#
has_one_attached :avatar
has_one_attached :avatar do |attachable|
attachable.variant :small, resize_to_fill: [64, 64]
attachable.variant :medium, resize_to_fill: [256, 256]
attachable.variant :large, resize_to_fill: [512, 512]
end
#
# Relations
@ -163,14 +167,6 @@ class User < ApplicationRecord
@display_name ||= ldap_entry[:display_name]
end
def avatar_64px
avatar.variant(resize_to_fill: [64, 64])
end
def avatar_256px
avatar.variant(resize_to_fill: [256, 256])
end
def services_enabled
ldap_entry[:service] || []
end

View File

@ -41,7 +41,7 @@
<div class="flex items-center gap-6">
<% if current_user.avatar.attached? %>
<p class="flex-none">
<%= image_tag current_user.reload.avatar_256px, class: "h-24 w-24 rounded-lg" %>
<%= image_tag current_user.reload.avatar.variant(:medium), class: "h-24 w-24 rounded-lg" %>
</p>
<% end %>
<div class="grow">