错误记录

文章目录

问题描述

实作Rails实战:招聘网站时6-2时,在Step 9 出现已添加管理员权限的人员依然无人登录后台的问题,出现提示消息You are not admin

Debug

仔细检查了下,原来是管理员权限判断时,if语句中少个!(逻辑非)

app/controllers/application_controller.rb
1
2
3
4
5
6
7
8
9
10
class < ActionController::Base
protect_from_forgery with: :exception
def require_is_admin
if !current_user.admin? //刚开始少了个!感叹号
flash[:alert] = 'You are not admin'
redirect_to root_path
end
end
end