28 lines
621 B
Ruby
28 lines
621 B
Ruby
# app/controllers/application_controller.rb
|
|
class ApplicationController < ActionController::Base
|
|
include Pundit::Authorization
|
|
|
|
before_action :authenticate_user!
|
|
before_action :set_tema
|
|
|
|
# Pundit: redireciona se não autorizado
|
|
rescue_from Pundit::NotAuthorizedError do |e|
|
|
flash[:alert] = "Você não tem permissão para realizar esta ação."
|
|
redirect_to root_path
|
|
end
|
|
|
|
private
|
|
|
|
def set_tema
|
|
@tema = current_user&.tema_preferido || 'dark'
|
|
end
|
|
|
|
def after_sign_in_path_for(resource)
|
|
if resource.motorista?
|
|
motorista_dashboard_path
|
|
else
|
|
dashboard_path
|
|
end
|
|
end
|
|
end
|