class ApplicationController < ActionController::Base before_action :set_current_request_details before_action :authenticate private def current_user Current.user || authenticate_user_from_session end helper_method :current_user def authenticate_user_from_session session_record = Session.find_by_id(cookies.signed[:session_token]) Current.session = session_record Current.user end def user_signed_in? current_user.present? end helper_method :user_signed_in? def authenticate unless user_signed_in? redirect_to sign_in_path end end def set_current_request_details Current.user_agent = request.user_agent Current.ip_address = request.ip end end