Skip to content

Instantly share code, notes, and snippets.

@m3talsmith
Created February 14, 2013 22:05
Show Gist options
  • Save m3talsmith/4956828 to your computer and use it in GitHub Desktop.
Save m3talsmith/4956828 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_to] : root_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment