相对较新的轨道,我有一个简单的Web应用程序使用Devise用户认证。一个属性是:admin
布尔值,对于大多数用户设置为nil
,我将在控制台中手动更改为true
,以供少数用户需要具有管理访问权限。设计:限制页面访问使用用户属性
我的问题是:我应该如何限制访问特定页面给管理员访问标记为true
的人?
我已经尝试了一些逻辑,在我pages_controller
,但它似乎并不重定向我根据需要(指user_list
部分):
class PagesController < ApplicationController
before_action :authenticate_user!, :except => [:welcome]
def welcome
#code removed for brevity's sake
end
def dashboard
#ditto
end
def user_list
unless
current_user.admin == true
redirect_to pages_dashboard_path
else
@users = Users.all
end
end
end
任何建议对我的方向或目标否则限制访问我的user_list
页面将不胜感激。
redirect_to pages_dashboard_path并返回。 –