class SessionsController < ApplicationController

  def new
  end

  def create
    user = User.find_by(name: session_params[:name])
    if user && user.authenticate(session_params[:password])
      session[:user_id] = user.id
      redirect_to root_path
    else
      flash.now[:error] = "Your login information was incorrect"
      redirect_to login_path
    end
  end

  def destroy
    session.clear
    redirect_to root_path
  end

  def session_params
    params.require(:session).permit(:name, :password)
  end

end
class SessionsController < ApplicationController

  def new
  end

  def create
    user = User.find_by(name: session_params[:name])
    if user && user.authenticate(session_params[:password])
      session[:user_id] = user.id
      redirect_to root_path
    else
      flash.now[:error] = "Your login information was incorrect"
      redirect_to root_path
    end
  end

  def destroy
    session.clear
    redirect_to root_path
  end

  def session_params
    params.require(:session).permit(:name, :password)
  end

end
Refactor routes with rails helper url methods
Refactor routes with rails helper url methods

Use root_path in #create and #destroy actions in sessions controller
