我正在使用 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 有什么方法可以使用控制器+动作而不是模型+动作吗?
Use authorize_resource :class => false
在你的控制器中。 CanCan 将自动检查控制器名称上的能力(作为符号、单数,例如:statistic
为了StatisticsController
)
See https://github.com/ryanb/cancan/wiki/Non-RESTful-Controllers https://github.com/ryanb/cancan/wiki/Non-RESTful-Controllers
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)