# frozen_string_literal: true class ApplicationController < ActionController::Base include Pundit::Authorization GIT_REV = lambda do path = Rails.root.join("REVISION") if path.exist? path.read.chomp[..6] else `git rev-parse --short HEAD`.chomp end end.call rescue_from Pundit::NotAuthorizedError, with: :rescue_from_pundit_not_authorized def redirect_not_found! raise ActionController::RoutingError.new("Not Found") end protected def guest_user @guest_user ||= User.guest_user end helper_method :guest_user def current_or_guest_user current_user || guest_user end helper_method :current_or_guest_user def pundit_user current_or_guest_user end private def rescue_from_pundit_not_authorized flash[:alert] = "You are not authorized to perform this action." redirect_back(fallback_location: root_path) end end