# app/controllers/application_controller.rb class ApplicationController < ActionController::Base include Pundit::Authorization before_action :authenticate_user! before_action :set_tema after_action :verify_authorized, except: :index, unless: :skip_pundit? after_action :verify_policy_scoped, only: :index, unless: :skip_pundit? rescue_from Pundit::NotAuthorizedError, with: :usuario_nao_autorizado protect_from_forgery with: :exception private def set_tema # Lê o tema da sessão (padrão: escuro) @tema = session[:tema] || 'dark' end def skip_pundit? devise_controller? || params[:controller] =~ /rails\/|action_mailbox|action_text/ end def usuario_nao_autorizado flash[:alert] = 'Acesso negado. Você não tem permissão para esta ação.' redirect_back(fallback_location: dashboard_path) end end