[英]cant get cancan to work on rails 3.1
I had a two month break using Rails and now its biting me when I return! 我使用Rails休息了两个月,现在当我回来时它咬了我!
I am trying to get CanCan to work on Rails 3.1 and have viewed the railscast and then followed their instructions on the cancan git page. 我试图让CanCan在Rails 3.1上工作,并查看了railscast,然后按照cancan git页面上的说明进行操作。 However when I try run the homepage it gives me the following error:
但是,当我尝试运行主页时,出现以下错误:
Routing Error
undefined local variable or method `authorize_resource' for StaticController:Class
How do I make this stop? 我该如何停止? Its as if cancan is not loaded, but I have installed it using bundler and it doesnt mention that I have to do anything else to include it.
好像没有加载cancan,但是我已经使用bundler安装了它,并且没有提到我必须做其他任何事情才能包含它。
Anyone have any ideas? 有人有想法么?
Sorry my bad! 对不起这是我的错! Too much coffee resulted in me not reading all the instructions for how to install it.
咖啡过多导致我无法阅读有关如何安装咖啡的所有说明。
I needed to add the following to my ApplicationController: 我需要将以下内容添加到我的ApplicationController中:
def current_ability
@current_ability ||= Ability.new(current_user)
end
and then I needed to use 然后我需要使用
class StaticController < ApplicationController
authorize_resource :class => false
Because in this particular example it was just a static simple homepage that sits infront of a more complicated web app. 因为在这个特定示例中,它只是一个静态的简单首页,位于更复杂的Web应用程序的前面。
Thanks for the help. 谢谢您的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.