Okay I have been working on this for about 2 hours and am sure there is a very simple solution but unfortunately as a rails novice I can’t seem to find it.
I have set up a basic sign up and login system following Ryan Bates Authetication lesson #270.
I keep however receiving the same error when trying to login.
undefined method `find_by_email' for nil:NilClass
I have my sessions controller set up as follows:
class SessionsController < ApplicationController
def new
end
def create
user = user.find_by_email(params[:email])
if user && user.authenticate(params[:password])
session[:user_id] = user.id
redirect_to root_url, :notice => "Logged in!"
else
flash.now.alert = "Invalid email or password"
render "new"
end
end
def destroy
session[:user_id] = nil
redirect_to root_url, :notice => "Logged Out!"
end
end
But am really unsure how to define find_by_email.
Any advice people can offer me on this really would be much appreciated
should be