From bac93f93a0b293eaaea5268268eb18f0c5a7c516 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Wed, 15 Oct 2014 13:41:47 -0400 Subject: [PATCH] Add login filter --- app/controllers/application_controller.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 543296f..ea6fab9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,4 +5,13 @@ class ApplicationController < ActionController::Base def current_user @current_user ||= User.find(session[:user_id]) if session[:user_id] end + + private + + def require_login + unless current_user + flash[:error] = 'You must be logged in to access this page' + redirect_to root_path + end + end end