Rails未初始化的常量ApplicationController :: SessionHelper

时间:2015-12-22 16:43:01

标签: ruby-on-rails ruby

我无法弄清楚我得到的这个错误:

ActionController::RoutingError (uninitialized constant ApplicationController::SessionHelper):
  app/controllers/application_controller.rb:3:in `<class:ApplicationController>'
  app/controllers/application_controller.rb:1:in `<top (required)>'
  app/controllers/static_pages_controller.rb:1:in `<top (required)>'

这是我的应用程序控制器:

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  include SessionHelper
end

我的sessions_helper.rb:

module SessionsHelper

  # Logs in the given user.
  def log_in(user)
    session[:user_id] = user.id
  end

  # Returns the current logged-in user (if any).
  def current_user
    @current_user ||= User.find_by(id: session[:user_id])
  end

  # Returns true if the user is logged in, false otherwise.
  def logged_in?
    !current_user.nil?
  end

end

1 个答案:

答案 0 :(得分:6)

拼写错误

include SessionsHelper