Last active
August 29, 2015 14:00
-
-
Save drager/be49169fffeddd101e06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= form_for(:user) do |f| | |
- if flash[:alert] | |
%div{class: 'alert'} | |
= flash[:alert] | |
= f.label :email | |
%div{class: 'field'} | |
= f.email_field :email | |
= f.label :password | |
%div{class: 'field'} | |
= f.password_field :password | |
%div{class: 'actions'} | |
= f.submit 'Login' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PG::UndefinedTable: ERROR: missing FROM-clause entry for table "email" LINE 1: SELECT "users".* FROM "users" WHERE "email"."email" = '' L... ^ : SELECT "users".* FROM "users" WHERE "email"."email" = '' LIMIT 1 | |
ON LINE: user = User.find_by(email: user_param_email).try(:authenticate, user_param_password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- title 'Login' | |
%h1 Login | |
= render 'form' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
#match 'login', to: 'sessions#new', as: 'session', via: [:get, :post] | |
get 'login', to: 'sessions#new', as: 'session' | |
post 'login', to: 'sessions#create', as: 'create_session' | |
get 'logout', to: 'sessions#destroy', as: 'destroy_session' | |
resources :users | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SessionsController < ApplicationController | |
def new | |
end | |
def create | |
user = User.find_by(email: params[:email]).try(:authenticate, params[:password]) | |
if user | |
session[:user_id] = user.id | |
redirect_to root_url, :notice => 'Logged in!' | |
else | |
flash.alert = 'Invalid email or password' | |
render 'new' | |
end | |
end | |
def destroy | |
session[:user_id] = nil | |
redirect_to root_url, notice: 'Logged out!' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment