Skip to content

Commit b637e82

Browse files
author
Ashley Yang
committed
Add admin permission logic to destroy action in users controller
1 parent 7cfab4f commit b637e82

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

app/controllers/users_controller.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ def create
3636
end
3737

3838
def destroy
39-
@user = User.find(params[:id])
40-
p @user
41-
@user.destroy
39+
if admin?
40+
@user = User.find(params[:id])
41+
@user.destroy
4242

43-
redirect_to users_path
43+
redirect_to users_path
44+
else
45+
flash[:not_admin] = "You do not have permission to view this page."
46+
redirect_to "/"
47+
end
4448
end
4549

4650
private

app/views/categories/index.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<h1 class='title'>Welcome to Chez Ken</h1>
22
<h3><%= flash[:notice] %></h3>
3+
<h3><%= flash[:not_admin] %></h3>
34

45
<div class='container'>
56
<div class='container col-4-md wd-17-m mg-0'>

0 commit comments

Comments
 (0)