Skip to content

Instantly share code, notes, and snippets.

@NoahSaso
Forked from tinogomes/redirect_back_or_default.rb
Last active August 19, 2017 09:03
Show Gist options
  • Save NoahSaso/ef02aba31bebf5fb642911498238b6f7 to your computer and use it in GitHub Desktop.
Save NoahSaso/ef02aba31bebf5fb642911498238b6f7 to your computer and use it in GitHub Desktop.
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