Created
February 16, 2016 01:12
-
-
Save armandofox/aa41855729c25875119a to your computer and use it in GitHub Desktop.
application_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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