Initial commit - Fase 1: Setup Rails + Docker
This commit is contained in:
27
app/controllers/application_controller.rb
Normal file
27
app/controllers/application_controller.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user