Skip to content

Instantly share code, notes, and snippets.

@Znow
Created March 26, 2011 11:19
Show Gist options
  • Select an option

  • Save Znow/888212 to your computer and use it in GitHub Desktop.

Select an option

Save Znow/888212 to your computer and use it in GitHub Desktop.
class SessionsController < ApplicationController
def new
@title = 'Sign In'
end
def create
# Use the authenticate method from the User model along with the parametres of :session to validate the user login
user = User.authenticate(params[:session][:email], params[:session][:password])
if user.nil?
flash.now[:error] = "Invalid email/password combination"
@title = "Sign in"
render 'new'
else
sign_in user # Signs in the User
redirect_back_or user
end
end
def destroy
sign_out
redirect_to root_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment