[英]Devise authenticate_user
帮助我解决这个问题:
我有2个模型(管理员和用户) - >用devise创建,我有post_controller:
问题出现了:
如果我有一个型号(user.rb) - >在我的控制器中我把它:
before_filter :authenticate_user!, :except => [:show, :index]
但我有2个模型,我希望用户可以访问帖子控制器的“显示”和“索引”操作,管理员可以访问所有操作。
我做了类似的事情:
before_filter :logged_in
.
.
.
private
def logged_in
if admin_signed_in?
else
authenticate_user!
end
end
但我想改变我的字符串:
authenticate_user!
这样的事情:
:authenticate_user!, :except => [:show, :index]
但除了指的是before_filter之外
我怎么能这样做(没有'cancan'宝石)
尝试使用两个前过滤器 - 一个用于管理员操作,另一个用于管理员或用户操作。
# ensure admin for other actions
before_filter :check_admin_logged_in!, :except => [:show, :index]
# ensure user or admin logged in for these actions (:only option is optional)
before_filter :check_user_logged_in!, :only => [:show, :index]
private
def check_admin_logged_in! # admin must be logged in
authenticate_admin!
end
def check_user_logged_in! # if admin is not logged in, user must be logged in
if !admin_signed_in?
authenticate_user!
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.