title: NoMethodError in SessionsController#create (undefined method `current_user) Hartl Chapter 9
body: <p>When i sign into the sample app i've made from Hartl's rail tutorial at the end of Chapter 9 i get this error. I've searched high and low but can't figure out what's probably very obvious.</p>
  
  <blockquote>
    <p>NoMethodError in SessionsController#create</p>
    
    <p><p>undefined method `current_user=' for #session....</p>
  </blockquote>
  
  <p>The errors occur in these 2 files, code below</p>
  
  <blockquote>
    <p>app/helpers/sessions_helper.rb:7:in <code>sign_in'
    app/controllers/sessions_controller.rb:9:in</code>create'</p>
  </blockquote>
  
  <p><strong>app/helpers/sessions_helper</strong></p>
  
  <pre><code>  module SessionsHelper
  
    def sign_in(user)
      remember_token = User.new_remember_token
      cookies.permanent[:remember_token] = remember_token
      user.update_attribute(:remember_token, User.encrypt(remember_token))
      self.current_user = user
    end
  
    def signed_in?
      !current_user.nil?
    end
  
    def current_user
      remember_token = User.encrypt(cookies[:remember_token])
      @current_user ||= User.find_by(remember_token: remember_token)
    end
  
    def current_user?(user)
      user == current_user
    end
  
    def sign_out
      self.current_user = nil
      cookies.delete(:remember_token)
    end
  
    def redirect_back_or(default)
      redirect_to(session[:return_to] || default)
      session.delete(:return_to)
    end
  
    def store_location
      session[:return_to] = request.url if request.get?
    end
  end
  </code></pre>
  
  <p><strong>app/controllers/sessions_controller</strong></p>
  
  <pre><code>class SessionsController &lt; ApplicationController
  
    def new
    end
  
    def create
      user = User.find_by(email: params[:session][:email].downcase)
      if user &amp;&amp; user.authenticate(params[:session][:password])
        sign_in user
        redirect_back_or user
      else
        flash.now[:error] = 'Invalid email/password combination'
        render 'new'
      end
    end
  
    def destroy
      sign_out
      redirect_to root_url
    end
  end
  </code></pre>