Skip to content

Instantly share code, notes, and snippets.

@armandofox
Created February 16, 2016 01:12
Show Gist options
  • Save armandofox/aa41855729c25875119a to your computer and use it in GitHub Desktop.
Save armandofox/aa41855729c25875119a to your computer and use it in GitHub Desktop.
application_controller.rb
class ApplicationController < ActionController::Base
before_filter :set_current_user
protected # prevents method from being invoked by a route
def set_current_user
# we exploit the fact that find_by_id(nil) returns nil
@current_user ||= Moviegoer.find_by_id(session[:user_id])
redirect_to login_path and return unless @current_user
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment