如何在current_user尝试在acl9中登录时拒绝访问?
问题描述:
我在我的rails3应用程序中使用acl9和authlogic。我想知道如何 -如何在current_user尝试在acl9中登录时拒绝访问?
当他试图创建新用户时阻止current_user?
是否允许superadmin创建新用户?
答
我对你的问题有点不清楚。如果您只想知道给定用户已登录,则在向新用户显示表单的控制器方法中,检查是否已设置current_user
,如果是,请设置一条闪烁的消息。例如,在,也许registrations_controller.rb
# show an empty registration form to user
def new
if current_user
flash[:notice] = "Hey #{current_user.name}, you're already logged in!"
return
end
... rest of normal controller code to create a registration form
end
如果你想防止非管理员用户创建新用户,你需要检查自己的角色,例如
unless current_user.has_role? :superadmin
flash[:warning] = "Sorry #{current_user.name}, I can't do that for you."
return
end