Files
fizzy/app/controllers/users/avatars_controller.rb
T
2025-02-12 13:19:53 +00:00

37 lines
793 B
Ruby

class Users::AvatarsController < ApplicationController
include ActiveStorage::Streaming
before_action :set_user
def show
fresh_when @user, cache_control: { max_age: 30.minutes, stale_while_revalidate: 1.week }
if @user.avatar.attached?
send_blob_stream @user.avatar
elsif @user.system?
render_system_avatar
else
render_initials
end
end
def destroy
@user.avatar.destroy
redirect_to user_path(@user)
end
private
def set_user
@user = Current.account.users.find(params[:user_id])
end
def render_system_avatar
send_file Rails.root.join("app/assets/images/system-avatar.svg"),
content_type: "image/svg+xml", disposition: :inline
end
def render_initials
render formats: :svg
end
end