Defined require_user_signed_in filter in application controller

This commit is contained in:
Prelang Builder
2014-02-27 23:58:25 +00:00
committed by u7482
parent b492b5fce0
commit 3626e2221f

View File

@@ -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