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 params[:return_to] || root_url, notice: "Logged in!" else flash[:warning] = "You have entered incorrect email and/or password." render :new end end def destroy session.delete(:user_id) redirect_to root_path end end