ruby-on-rails – CanCan和没有型号的控制器

我正在使用CanCan进行授权.我在/app/config/ability.rb中定义了模型动作用户规则,它的工作正常.我已经将load_and_authorize_resource行添加到我的application_controller中,一切都完成了.

但是,我也有许多视图和控制器没有下面的模型.例如,尝试加载统计页面

NameError (uninitialized constant Statistic):
  activesupport (3.2.3) lib/active_support/inflector/methods.rb:229:in `block in constantize'
  activesupport (3.2.3) lib/active_support/inflector/methods.rb:228:in `each'
  activesupport (3.2.3) lib/active_support/inflector/methods.rb:228:in `constantize'
  ...

CanCan有没有办法使用控制器动作而不是模型动作?

解决方法

使用authorize_resource:class =>在您的控制器中为false. CanCan将自动检查控制器名称的能力(作为一个符号,单数,例如:统计控制器的统计)

https://github.com/ryanb/cancan/wiki/Non-RESTful-Controllers

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...