非常基本的用户模型,我希望管理用户:管理所有CanCan宝石|不能:索引,用户
其他不能:索引,用户和其他选项,但是当我试图阻止非管理员用户查看用户索引,admin用户也无法访问。
这是我ability.rb
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new #guest user
can :manage, :all if user.role == "admin" #if user.admin? can :manage, :all
can :assign_role, User
else
can :read, :all
can :create, User
cannot :assign_role, User
cannot :index, User
can [:show, :edit, :update], User do |current_user|
user.id == current_user.id || user.role == "admin"
end
end
end
我能做些什么来阻止被阻止所有用户都从用户的索引?
问候
丹
不错的代码汤那里。那还有什么关系? – tadman 2010-03-02 23:09:46