Added ability to change user roles in admin/users index

This commit is contained in:
2024-09-18 10:42:12 +02:00
parent ace50699fb
commit a169b8fae8
6 changed files with 35 additions and 15 deletions

View File

@@ -1,6 +1,6 @@
class Admin::UsersController < ApplicationController
before_action :set_user, only: [ :show, :update ]
before_action :authorize!
before_action :set_user, only: [ :show, :edit ]
def index
@users = User.all.order(:lastname, :firstname)
@@ -20,6 +20,14 @@ class Admin::UsersController < ApplicationController
end
def update
authorize! @user
if @user.update(user_params)
respond_to do |format|
format.html { redirect_to admin_users_path }
end
else
render :index, status: :unprocessable_entity
end
end
private
@@ -27,4 +35,8 @@ class Admin::UsersController < ApplicationController
def set_user
@user = User.find(params[:id])
end
def user_params
params.require(:user).permit(:role)
end
end