Forked from tinogomes/redirect_back_or_default.rb
Last active
August 19, 2017 09:03
-
-
Save NoahSaso/ef02aba31bebf5fb642911498238b6f7 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
class ApplicationController < ActionController::Base | |
helper :all # include all helpers, all the time | |
protect_from_forgery | |
private | |
def require_user | |
unless @current_user | |
store_location | |
flash[:notice] = "You must be logged in to access this page" | |
redirect_to login_url | |
return false | |
end | |
end | |
def require_no_user | |
if @current_user | |
store_location | |
flash[:notice] = "You must be logged out to access this page" | |
redirect_to logout_url | |
return false | |
end | |
end | |
def store_location | |
session[:return_to] = request.fullpath | |
end | |
def redirect_back_or_default(default = root_url, options = {}) | |
redirect_to(session.delete(:return_to) || default, options) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment