0
这是我的能力和我有限的用户,所以他们只能阅读他们自己的。但是如果我经过路线,我仍然可以看到其他用户的索引。cancan方法和设计
我不想将当前用户放在索引路由中,因为我将限制管理用户,因为我必须对模型,管理员和用户进行限制。
class Ability
include CanCan::Ability
def initialize(user)
if user.is_a?(Admin)
can :manage, :all
elsif user.is_a?(User)
can :show, Profile
can :read, Profile do |profile|
profile.try(:user) == user
end
can :update, Profile do |profile|
profile.try(:user) == user
end
can :destroy, Profile do |profile|
profile.try(:user) == user
end
can :create, Profile
else
can :show, Profile
cannot :destroy
cannot :create
end
end
end