Class: RolesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/roles_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

This method creates role objects



27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/roles_controller.rb', line 27

def create
  @managing_user = User.find(params[:user_id])
  if params[:game]
    game = Game.find_by(name: params[:game])
    Role.create!(role: params[:role], user_id: @managing_user.id, game_id: game.id)
  else
    Role.create!(role: params[:role], user_id: @managing_user.id)
  end
  redirect_to roles_path(user_id: @managing_user.id), notice: "Assigned role to user"
end

#destroyObject

This method destroys role objects



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/roles_controller.rb', line 13

def destroy
  @managing_user = User.find(params[:user_id])
  if params[:id] == "destroy_many"
    role = Role.where(role: params[:role], user_id: @managing_user.id).destroy_all
    SettingsService.remove_role(@managing_user, params[:role], "any")
  else
    role = Role.find(params[:id])
    SettingsService.remove_role(@managing_user, role.role, role.game ? role.game.name : "")
    role.destroy!
  end
  redirect_to roles_path(user_id: @managing_user.id), notice: "Removed role from user"
end

#indexObject

before_action :check_session_id_admin, only: %i[ index ] This method sets the user whose roles will be edited



4
5
6
7
8
9
10
# File 'app/controllers/roles_controller.rb', line 4

def index
  if params[:user_id].nil?
    redirect_to games_path
  else
    @managing_user ||= User.find(params[:user_id])
  end
end