下面是我的能力文件。
在大多数控制器中,如果我想应用cancan,我只需要将load_and_authorize_resource
控制器放在开头即可。
如果我想制作一个名为 ABC 的特定控制器,并且不允许用户运行索引操作(即显示)怎么办?
有任何想法吗?
class Ability
include CanCan::Ability
def basic_read_only
can :read, :all
can :list, :all
can :search, :all
end
def basic_operation
can :read, :all
can :list, :all
# can :edit, :all
can :create, :all
can :search, :all
end
def initialize(user)
if user.blank?
# user.role == 'guest'
cannot :manage, :all
basic_read_only
else
if 'admin' == user.role
can :manage, :all
else
# cannot :manage, :all
# basic_read_only
basic_operation
end
end
end
end