Skip to content

Instantly share code, notes, and snippets.

@tinogomes
Created February 19, 2009 00:25
Show Gist options
  • Save tinogomes/66633 to your computer and use it in GitHub Desktop.
Save tinogomes/66633 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.request_uri
end
def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment