FIX auto generate avatar bug

This commit is contained in:
jasder 2021-04-19 17:28:57 +08:00
parent b6e8a135f0
commit 21befb6486
3 changed files with 11 additions and 6 deletions

View File

@ -149,7 +149,7 @@ module ApplicationHelper
File.join("images/avatars", ["#{source.class}", "#{source.id}"]) + "?t=#{ctime}"
end
elsif source.class.to_s == 'User'
source.letter_avatar_url
source.get_letter_avatar_url
end
end

View File

@ -1,18 +1,23 @@
require 'letter_avatar/has_avatar'
require 'chinese_pinyin'
class User
module Avatar
extend ActiveSupport::Concern
include LetterAvatar::HasAvatar
def name
lastname.blank? ? login : Pinyin.t(lastname)
def username
self.lastname.blank? ? self.login : Pinyin.t(self.lastname)
end
def letter_avatar_url(size = :lg)
avatar_url(avatar_size(size))
def get_letter_avatar_url(size = :lg)
avatar_path(size).split('public/')&.last
end
def avatar_path(size)
LetterAvatar.generate self.username, avatar_size(size)
end
# 返回头像尺寸
# xs: 22px
# sm: 32px

View File

@ -3,5 +3,5 @@ LetterAvatar.setup do |config|
config.cache_base_path = 'public/system/lets' # default is 'public/system'
config.colors_palette = :iwanthue # default is :google
config.annotate_position = '-0+10' # default is -0+5
config.letters_count = 2 # default is 1
# config.letters_count = 2 # default is 1
end