43069b1ea4
Good code smell is when the before_action callbacks stack up but can't be shared across actions
34 lines
635 B
Ruby
34 lines
635 B
Ruby
class UsersController < ApplicationController
|
|
before_action :set_user, only: %i[ show edit update destroy ]
|
|
before_action :ensure_permission_to_change_user, only: %i[ update destroy ]
|
|
|
|
def edit
|
|
end
|
|
|
|
def show
|
|
end
|
|
|
|
def update
|
|
@user.update! user_params
|
|
redirect_to @user
|
|
end
|
|
|
|
def destroy
|
|
@user.deactivate
|
|
redirect_to users_path
|
|
end
|
|
|
|
private
|
|
def set_user
|
|
@user = User.active.find(params[:id])
|
|
end
|
|
|
|
def ensure_permission_to_change_user
|
|
head :forbidden unless Current.user.can_change?(@user)
|
|
end
|
|
|
|
def user_params
|
|
params.expect(user: [ :name, :avatar ])
|
|
end
|
|
end
|