Skip to content

Instantly share code, notes, and snippets.

@ellijayne
Created July 14, 2018 11:31
Show Gist options
  • Save ellijayne/65c4b05d268469a766c44211a7e8884d to your computer and use it in GitHub Desktop.
Save ellijayne/65c4b05d268469a766c44211a7e8884d to your computer and use it in GitHub Desktop.
session controller
class SessionController < ApplicationController
def new
end
def create
user = User.find_by :username => params[:username]
if user.present? && user.authenticate(params[:password])
session[:user_id] = user.id
redirect_to root_path
else
flash[:error] = "Invalid username or password entered"
redirect_to login_path
end
end
def destroy
session[:user_id] = nil
redirect_to root_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment