Skip to content

Instantly share code, notes, and snippets.

@brobertsaz
Forked from m3talsmith/protected_controller.rb
Last active December 13, 2015 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brobertsaz/4961421 to your computer and use it in GitHub Desktop.
Save brobertsaz/4961421 to your computer and use it in GitHub Desktop.
class ProtectedController << ApplicationController
before_filter :force_user
def index
end
private
def force_user
unless session[:user_id]
session[:redirect_url] = request.fullpath
redirect_to new_sessions_path
end
end
end
class SessionsController << ApplicationController
def create
session[:user_id] = User.first.id
redirect_to session[:redirect_url] ? session[:redirect_url] : root_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment