Skip to content

Instantly share code, notes, and snippets.

@drager
Last active August 29, 2015 14:00
Show Gist options
  • Save drager/be49169fffeddd101e06 to your computer and use it in GitHub Desktop.
Save drager/be49169fffeddd101e06 to your computer and use it in GitHub Desktop.
= 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'
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)
- title 'Login'
%h1 Login
= render 'form'
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
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