Skip to content

Instantly share code, notes, and snippets.

@LukeHackett
Created August 1, 2014 15:35
Show Gist options
  • Save LukeHackett/7a200afae0645a189a0b to your computer and use it in GitHub Desktop.
Save LukeHackett/7a200afae0645a189a0b to your computer and use it in GitHub Desktop.
yolo
def require_user
unless current_user
store_location
flash[:danger] = "You must be logged in to access this page"
redirect_to login_path
return false
end
end
def require_no_user
if current_user
store_location
flash[:danger] = "You must be logged out to access this page"
redirect_to logout_path
return false
end
end
def store_location
session[:return_to] = request.original_url
end
def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment