roles_controller.rb 653 B

123456789101112131415161718192021222324252627282930313233
  1. # frozen_string_literal: true
  2. module Admin
  3. class Users::RolesController < BaseController
  4. before_action :set_user
  5. def show
  6. authorize @user, :change_role?
  7. end
  8. def update
  9. authorize @user, :change_role?
  10. @user.current_account = current_account
  11. if @user.update(resource_params)
  12. redirect_to admin_account_path(@user.account_id), notice: I18n.t('admin.accounts.change_role.changed_msg')
  13. else
  14. render :show
  15. end
  16. end
  17. private
  18. def set_user
  19. @user = User.find(params[:user_id])
  20. end
  21. def resource_params
  22. params.require(:user).permit(:role_id)
  23. end
  24. end
  25. end