0

我正在阅读教程并收到此错误:

.../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

session_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) }

...

任何帮助和解释什么是错误的以及如何解决它将不胜感激。

4

1 回答 1

0

换成include ::SessionsHelper这个include SessionsHelper

于 2013-08-15T13:28:08.880 回答