From 3626e2221f6cf80df56b355f0c0ff47c1fcd4e50 Mon Sep 17 00:00:00 2001 From: Prelang Builder Date: Thu, 27 Feb 2014 23:58:25 +0000 Subject: [PATCH] Defined require_user_signed_in filter in application controller --- app/controllers/application_controller.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e..fab5591 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,25 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + + private + + #-> Prelang (user_login:devise) + def require_user_signed_in + unless user_signed_in? + + # If the user came from a page, we can send them back. Otherwise, send + # them to the root path. + if request.env['HTTP_REFERER'] + fallback_redirect = :back + elsif defined?(root_path) + fallback_redirect = root_path + else + fallback_redirect = "/" + end + + redirect_to fallback_redirect, flash: {error: "You must be signed in to view this page."} + end + end + end