2013-08-01 43 views
1

我做迈克尔·哈特的教程中,我得到的错误:为什么我会得到“未初始化的常量ApplicationController :: SessionsHelper(NameError)”?

rails_projects/sample_app/app/controllers/application_controller.rb:3:in `<class:ApplicationController>': uninitialized constant ApplicationController::SessionsHelper (NameError) 

这里是我的application_controller.rb文件:

class ApplicationController < ActionController::Base 
    protect_from_forgery 
    include SessionsHelper 

    # Force signout to prevent CSRF attacks 
    def handle_unverified_request 
    sign_out 
    super 
    end 
end 

回答

3

你应该有一个应用程序文件名为/帮手“sessions_helper。 RB”。里面的,你至少应该有这样的代码:

module SessionsHelper 
end 

我希望帮助。

+0

谢谢。现在我得到了错误:未定义的方法主题为主:对象(NoMethodError) – user2415183

+0

你能接受这个答案,并单独问你的新问题吗? –

0

你是从哪里定义的SessionHelper?如果它是在顶层模块,试试这个:

include ::SessionHelper 
1

不知道,如果你得到了答案,但我能出评论的sessionhelper线,并得到我的工作。我不知道这是否有深远的影响,但它现在帮助我绕开这个问题。

0

变化包括SessionsHelper包括SessionHelper 删除小号

+1

如果有人来自谷歌 - 这个答案是完全错误的。它应该是_include SessionsHelper_ – Lotix

0

我有同样的问题。确保你已经运行一次部署到heroku的迁移:

heroku run rake db:migrate 
相关问题