title: Ruby on Rails tutorial Chapter 8.1.5 undefined method 'find_by'
body: <p>I have finished the first section of chapter 8, only to be greeted with these 2 errors:</p>
  
  <pre><code>Failures:
  
    1) Authentication signin with invalid information 
       Failure/Error: before { click_button "Sign in" }
       NoMethodError:
         undefined method `find_by' for #&lt;Class:0xab805ec&gt;
       # ./app/controllers/sessions_controller.rb:7:in `create'
       # (eval):2:in `click_button'
       # ./spec/requests/authentication_pages_spec.rb:18:in `block (4 levels) in &lt;top  required)&gt;'
  
    2) Authentication signin with invalid information 
       Failure/Error: before { click_button "Sign in" }
       NoMethodError:
         undefined method `find_by' for #&lt;Class:0xab805ec&gt;
       # ./app/controllers/sessions_controller.rb:7:in `create'
       # (eval):2:in `click_button'
       # ./spec/requests/authentication_pages_spec.rb:18:in `block (4 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>The required files:</p>
  
  <p>sessions_controller</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 the user in and redirect to the user's show page.
      else
        flash.now[:error] = 'Invalid email/password combination'
        render 'new'
      end
    end
  
    def destroy
    end
  end
  </code></pre>
  
  <p>authentication pages spec</p>
  
  <pre><code>require 'spec_helper'
  
  describe "Authentication" do
  
   subject { page }
  
   describe "signin page" do
     before { visit signin_path }
  
     it { should have_content('Sign in') }
     it { should have_title('Sign in') }
   end
  
   describe "signin" do
     before { visit signin_path }
  
     describe "with invalid information" do
       before { click_button "Sign in" }
  
       it { should have_title('Sign in') }
       it { should have_selector('div.alert.alert-error', text: 'Invalid') }
     end
  
       describe "after visiting another page" do
         before { click_link "Home" }
         it { should_not have_selector('div.alert.alert-error') }
       end
     end
  
     describe "with valid information" do
       let(:user) { FactoryGirl.create(:user) }
       before do
         fill_in "Email",    with: user.email.upcase
         fill_in "Password", with: user.password
         click_button "Sign in"
      end
  
      it { should have_title(user.name) }
      it { should have_link('Profile',     href: user_path(user)) }
      it { should have_link('Sign out',    href: signout_path) }
      it { should_not have_link('Sign in', href: signin_path) }
      end
  
  end 
  </code></pre>
  
  <p>I started researching by putting in various snippets of the error and read through similar questions and tried their solutions but to no avail. Even staring at the code, I figured out the problem is to do with the create method inside sessions controller and specifically find_by method. Being fairly new to rails and to its concepts I am still puzzled. Any help and an explanation would be greatly appreciated.</p>