1

这是我的控制器:

class AdminController < ApplicationController
  before_filter :require_user
  authorize_resource :class => false

  def index
  end

  def users_list
  end

end

这是我的能力课:

class Ability
  include CanCan::Ability

  def initialize(user)
    if user.admin?
      can :manage, :all
    else
      can :read, :all
    end
  end
end

当尝试访问“/admin/users_list”(有或没有管理员用户)时,我收到以下错误:

未初始化的常量 CanCan::Rule::Mongoid

有什么想法吗?

4

1 回答 1

1

就在最近,CanCan添加了对 Mongoid的支持并重命名CanDefinitionRule,因此您收到的错误表明您正在使用来自 git repo 的最新 CanCan 代码。

试试 ruby​​gems 的 CanCan 1.4 版,看看是否能解决问题。在 ruby​​gems 发布 1.5 之前,可能需要修复一些错误。

更新:

此错误已在 CanCan 版本 1.5.0.beta1 中修复。

于 2010-12-26T05:45:32.430 回答