以下是条件
我users
有谁属于一个work
,同样category
属于一个work
。
现在我希望该特定作品的用户edit
属于该作品的类别。
如何在ability
模型中指定它?
编辑 :
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user
user.roles.each do |role|
role.name
if role.name == "admin"
can :read, User
can :create, User
can :edit, User
can :destroy, User
end
if role.name == "staff"
can :read, :all
can :create, :all
cannot :edit, Category
can :update, :all
can :destroy, :all
end
if role.name == "others"
can :read, :all
end
end
end
end