-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathusers_controller.rb
More file actions
47 lines (39 loc) · 933 Bytes
/
users_controller.rb
File metadata and controls
47 lines (39 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Admin::UsersController < ApplicationController
layout "admin"
before_action :require_admin
before_action :find_user, except: [:index]
def index
@users = User.all
end
def update
if @user == current_user
flash[:error] = "You cannot change the logged in user."
else
@user.admin = [email protected]
@user.save
end
redirect_to admin_users_path
end
def destroy
if @user == current_user
flash[:error] = "You cannot delete the logged in user."
else
@user.destroy
end
redirect_to admin_users_path
end
def block
@user.update_attributes(is_blocked: true)
flash[:notice] = "User is blocked"
redirect_to admin_users_path
end
def unblock
@user.update_attributes(is_blocked: false)
flash[:notice] = "User is unblocked"
redirect_to admin_users_path
end
private
def find_user
@user = User.find(params[:id])
end
end