Files
fizzy/app/controllers/users/avatars_controller.rb
T
Kevin McConnell f50a880d6b Avoid double render in Avatars#show
After sending the conditional 304 response, we were still attempting to
render the response, which is unnecessary.
2025-03-12 09:05:50 +00:00

34 lines
663 B
Ruby

class Users::AvatarsController < ApplicationController
include ActiveStorage::Streaming
before_action :set_user
def show
if stale? @user, cache_control: { max_age: 30.minutes, stale_while_revalidate: 1.week }
render_avatar_or_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_avatar_or_initials
if @user.avatar.attached?
send_blob_stream @user.avatar
else
render_initials
end
end
def render_initials
render formats: :svg
end
end