thirteen-tien-len/app/controllers/users_controller.rb
2023-11-06 05:21:19 +00:00

38 lines
743 B
Ruby

class UsersController < ApplicationController
before_action :authenticate_user!
after_action :verify_authorized
def index
@users = policy_scope User.all
authorize @users
end
def show
@user = User.find(params[:id])
authorize @user
end
def update
@user = User.find(params[:id])
authorize @user
if @user.update_attributes(secure_params)
redirect_to users_path, notice: 'User updated.'
else
redirect_to users_path, alert: 'Unable to update user.'
end
end
def destroy
user = User.find(params[:id])
authorize user
user.destroy
redirect_to users_path, notice: 'User deleted.'
end
private
def secure_params
params.require(:user).permit(:role)
end
end