Class: Gatepass::UsersController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /users



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/gatepass/users_controller.rb', line 49

def create
  @user = User.new(user_params)

  @current_user = session[:user]
  if @current_user['rolename'] != 'admin'
    redirect_to  users_url, notice: "You must be an admin to create a new user"
  end

  if @user.save
    redirect_to @user, notice: "User was successfully created."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject

DELETE /users/1



80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/gatepass/users_controller.rb', line 80

def destroy

  @current_user = session[:user]
  if @current_user['rolename'] != 'admin'
    redirect_to  users_url, notice: "You must be an admin to delete a new user"
  end

  @user.destroy
  redirect_to users_url, notice: "User was successfully destroyed.", status: :see_other
end

#editObject

GET /users/1/edit



40
41
42
43
44
45
46
# File 'app/controllers/gatepass/users_controller.rb', line 40

def edit

  @current_user = session[:user]
  if @current_user['rolename'] != 'admin'
    redirect_to  users_url, notice: "You must be an admin to edit a user"
  end
end

#indexObject

GET /users



11
12
13
14
15
16
17
18
# File 'app/controllers/gatepass/users_controller.rb', line 11

def index
  @users = User.all

  @current_user = session[:user]
  if @current_user['rolename'] != 'admin'
    @users = @users.where(:id => @current_user[:id])
  end
end

#newObject

GET /users/new



30
31
32
33
34
35
36
37
# File 'app/controllers/gatepass/users_controller.rb', line 30

def new
  @user = User.new

  @current_user = session[:user]
  if @current_user['rolename'] != 'admin'
    redirect_to  users_url, notice: "You must be an admin to create a new user"
  end
end

#showObject

GET /users/1



21
22
23
24
25
26
27
# File 'app/controllers/gatepass/users_controller.rb', line 21

def show

  @current_user = session[:user]
  if @current_user['rolename'] != 'admin' and @user[:id] != @current_user[:id]
    redirect_to  users_url, notice: "You must be an admin to view users"
  end
end

#updateObject

PATCH/PUT /users/1



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/gatepass/users_controller.rb', line 65

def update

  @current_user = session[:user]
  if @current_user['rolename'] != 'admin'
    redirect_to  users_url, notice: "You must be an admin to update a new user"
  end

  if @user.update(user_params)
    redirect_to @user, notice: "User was successfully updated."
  else
    render :edit, status: :unprocessable_entity
  end
end