-1
我有一个基本的授权类在Rails应用程序,它看起来是这样的:什么是:管理,:所有在Ruby中做的事情?
class Ability
include CanCan::Ability
def initialize(user)
if user
can :access, :rails_admin # only allow admin users to access Rails Admin
can :dashboard
if user.admin?
can :manage, :all
else
can :manage, [Agreement, Attachment, Contact, Deadline, Event, Image, Photo, Project, Submission, Talk]
can :update, User, id: user.id
end
end
# Current user cannot delete his account
cannot :destroy, User, id: user.id
end
end
现在,我在尝试用一个简单的用户访问仪表板时,未授权的错误,但一旦我把can :manage, :all
一个简单用户的状态它神秘地通过并看到仪表板。
什么是:manage, :all
有超过:manage, [All_my_tables]
,为什么我的用户不让用这种方式?
** HTTPS之前得到了很好的研究://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities** –
谢谢分享我的维基,但我已经通过该页面,如果我能找到我的答案,我不会在这里发布问题 –
*“我试图访问仪表板时遇到未经授权的错误”* - 这是不是因为你写了'can:dashboard'而不是'can:read,:dashboard'?或者,如果没有,您能否更具体地说明用户未经授权的行为? (什么是控制器?) –