Skip to content

Instantly share code, notes, and snippets.

@nicedawg
Created February 25, 2020 01:48
Show Gist options
  • Save nicedawg/430d678348add4c767c5910fe2f41664 to your computer and use it in GitHub Desktop.
Save nicedawg/430d678348add4c767c5910fe2f41664 to your computer and use it in GitHub Desktop.
[Beginning Rails 6] Listing 8-16. The create Method in app/controllers/sessions_controller.rb
class SessionsController < ApplicationController
def create
if user = User.authenticate(params[:email], params[:password])
session[:user_id] = user.id
redirect_to root_path, notice: "Logged in successfully"
else
flash.now[:alert] = "Invalid login/password combination"
render :new
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment