在 ruby 中使用 cancan 时出错:“未初始化的常量 CanCan::Rule::Mongoid”
这是我的控制器:
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
有什么想法吗?
here is my controller:
class AdminController < ApplicationController
before_filter :require_user
authorize_resource :class => false
def index
end
def users_list
end
end
here is my Ability class:
class Ability
include CanCan::Ability
def initialize(user)
if user.admin?
can :manage, :all
else
can :read, :all
end
end
end
when trying to access "/admin/users_list" (with an admin user or without) i get the following error:
uninitialized constant CanCan::Rule::Mongoid
any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就在最近,CanCan 添加了对 Mongoid 和 将
CanDefinition
重命名为Rule
,因此您收到的错误表明您正在使用来自 git 存储库的最新 CanCan 代码。尝试 rubygems 的 CanCan 1.4 版,看看是否可以解决问题。在 1.5 发布到 rubygems 之前可能需要修复一些错误。
更新:
此错误已在 CanCan 版本 1.5.0.beta1 中修复。
Just recently, CanCan added support for Mongoid and renamed
CanDefinition
toRule
, so the error you are getting indicates you are using the latest CanCan code from the git repo.Try out CanCan version 1.4 from rubygems and see if that solves the problem. There may be some bug fixes needed before 1.5 is released to rubygems.
UPDATE:
This bug was fixed in CanCan version 1.5.0.beta1.