2013-08-01 45 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 
相關問題