Skip to content

Instantly share code, notes, and snippets.

@haberbyte
Created March 22, 2019 18:05
Show Gist options
  • Save haberbyte/33864694cb03d02bcd281c57f220a521 to your computer and use it in GitHub Desktop.
Save haberbyte/33864694cb03d02bcd281c57f220a521 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
class Settings::AvatarsController < SettingsController
before_action :set_person
before_action :set_avatar
def create
@avatar = @person.avatar || Avatar.new(user: current_user)
@avatar.update avatar_params.merge(crop_x: nil, crop_y: nil, crop_width: nil, crop_height: nil)
redirect_to profile_path
end
def show
if @avatar.persisted?
redirect_to url_for(@avatar.default(size: params[:size]))
else
send_data identicon.read, disposition: "inline"
end
end
def update
@avatar.update(avatar_params)
redirect_to profile_path
end
def destroy
@avatar.destroy
redirect_to profile_path
end
private
def avatar_params
params.require(:avatar).permit(:image, :crop_x, :crop_y, :crop_width, :crop_height)
end
def set_person
@person = current_account.people.find(params[:person_id])
end
def set_avatar
@avatar = @person.avatar || Avatar.new(user: @person.user)
end
def identicon
@avatar.identicon(size: params[:size])
end
end
# frozen_string_literal: true
class SettingsController < ApplicationController
before_action :set_sidebar
append_view_path "app/views/settings"
private
def set_sidebar
@sidebar = :settings
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment