Skip to content

Instantly share code, notes, and snippets.

@jgaskins
Created March 8, 2016 19:55
Show Gist options
  • Save jgaskins/fb8f8498213b5580b29d to your computer and use it in GitHub Desktop.
Save jgaskins/fb8f8498213b5580b29d to your computer and use it in GitHub Desktop.
ActiveRecord has_secure_password
$ rails g model User email password_digest
class User < ActiveRecord::Base
has_secure_password
end
class SessionsController < ApplicationController
def create
user = User.find_by(email: params[:email])
if user && user.authenticate(params[:password])
login(user)
redirect_to root_url, notice: 'Signed in successfully'
else
flash.alert 'Email and password do not match'
render :new
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment