Ruby on Rails第8.2.1章未初始化的常量SessionsHelper(NameError)

时间:2013-08-15 12:01:03

标签: ruby-on-rails ruby

我正在完成本教程并收到此错误:

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

我尝试再次输入代码,但无济于事,猜测我可能会在某个地方输入错字。我研究了类似的问题,但它们要么太不同,要么我不理解给出的解决方案。

这是相关的代码:

应用程序控制器

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

sessions_controller

class SessionsController < ApplicationController

  def new
  end

  def create
    user = User.find_by_email(params[:session][:email].downcase)
    if user && user.authenticate(params[:session][:password])
     # Sign the user in and redirect to the user's show page.
      sign_in user
      redirect_to user
    else
     flash.now[:error] = 'Invalid email/password combination'
     render 'new'
    end
  end

  def destroy
  end
end

用户页面规范

require 'spec_helper'

describe User do

before do
  @user = User.new(name: "Example User", email: "user@example.com",
                   password: "foobar", password_confirmation: "foobar" )

end

subject { @user }

it { should respond_to(:name) }
it { should respond_to(:email) }
it { should respond_to(:password_digest) }
it { should respond_to(:password) }
it { should respond_to(:password_confirmation) }
it { should respond_to(:remember_token) }
it { should respond_to(:authenticate) }

...

任何有关错误以及如何解决问题的帮助和解释都将非常感激。

1 个答案:

答案 0 :(得分:0)

将此include ::SessionsHelper

替换为include SessionsHelper