新手问题 使用 Cancan 报的一个错误

mistbow · 2013年04月18日 · 最后由 mistbow 回复于 2013年04月18日 · 2413 次阅读

首先是我的代码:

class ApplicationController < ActionController::Base
  protect_from_forgery

  rescue_from Cancan::AccessDenied do |exception|
    flash[:error] = "Access denied"
    redirect_to root_url
  end
end

当我运行一个 deny 页面的时候,出现如下错误:

uninitialized constant ApplicationController::Cancan

SO 的这篇文章是这么说的:http://stackoverflow.com/questions/11315608/uninitialized-constant-applicationcontrollercancan-nameerror-in-production

但是我是直接用 rails s 测试运行的,是不是 webrick 也有不加载的问题呢?

bundle 了么?

#1 楼 @zgm 肯定 bundle 啦

bundle 信息: Using rake (10.0.4) Using i18n (0.6.4) Using multi_json (1.7.2) Using activesupport (3.2.11) Using builder (3.0.4) Using activemodel (3.2.11) Using erubis (2.7.0) Using journey (1.0.4) Using rack (1.4.5) Using rack-cache (1.2) Using rack-test (0.6.2) Using hike (1.2.2) Using tilt (1.3.7) Using sprockets (2.2.2) Using actionpack (3.2.11) Using mime-types (1.22) Using polyglot (0.3.3) Using treetop (1.4.12) Using mail (2.4.4) Using actionmailer (3.2.11) Using arel (3.0.2) Using tzinfo (0.3.37) Using activerecord (3.2.11) Using activeresource (3.2.11) Using bcrypt-ruby (3.0.1) Using cancan (1.6.9) Using coffee-script-source (1.6.2) Using execjs (1.4.0) Using coffee-script (2.2.0) Using rack-ssl (1.3.3) Using json (1.7.7) Using rdoc (3.12.2) Using thor (0.18.1) Using railties (3.2.11) Using coffee-rails (3.2.2) Using commonjs (0.2.6) Using orm_adapter (0.4.0) Using warden (1.2.1) Using devise (2.2.3) Using jquery-rails (2.2.1) Using less (2.3.1) Using less-rails (2.3.2) Using libv8 (3.11.8.17) Using mysql2 (0.3.11) Using bundler (1.2.3) Using rails (3.2.11) Using ref (1.0.4) Using sass (3.2.7) Using sass-rails (3.2.6) Using simple_form (2.1.0) Using therubyracer (0.11.4) Using twitter-bootstrap-rails (2.2.6) Using uglifier (2.0.1)

rails c 里面 执行 Cancan 呢

#4 楼 @zgm 怎么执行呢?

#4 楼 @zgm 界面里使用 can 这种可以

我擦 是 CanCan 啊

#7 楼 @zgm 啊 你以为。。。

#9 楼 @mistbow 我说你单词拼错了

是 Can Can

#11 楼 @zgm 你说 controller 里面的?

#11 楼 @zgm 擦 发现了。。。。

恩,你看文档啊

怪不得没人回这贴子

#14 楼 @zgm 嗯嗯 哥 我错了。。。。我这个还照这 192 这个教程对比了 3 遍呢 哎

需要 登录 后方可回复, 如果你还没有账号请 注册新账号