2024-08-04 07:06:03 +02:00
|
|
|
class ApplicationController < ActionController::Base
|
2025-04-23 07:45:33 +02:00
|
|
|
before_action :set_locale
|
|
|
|
|
|
2024-08-06 14:16:40 +02:00
|
|
|
private
|
2025-02-17 19:12:40 +01:00
|
|
|
|
2025-04-23 07:45:33 +02:00
|
|
|
def set_locale
|
|
|
|
|
I18n.locale = params[:locale] || session[:locale] || I18n.default_locale
|
|
|
|
|
session[:locale] = I18n.locale
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Optional: Make locale persist across requests via URL helpers
|
|
|
|
|
def default_url_options
|
|
|
|
|
{ locale: I18n.locale }
|
|
|
|
|
end
|
|
|
|
|
|
2024-08-06 14:16:40 +02:00
|
|
|
def set_company
|
2025-04-24 05:20:14 +00:00
|
|
|
# This should be handled by your authentication system
|
|
|
|
|
# But for now, we'll use a placeholder
|
|
|
|
|
company_id = session[:company_id]
|
|
|
|
|
|
|
|
|
|
unless company_id && Company.exists?(company_id)
|
|
|
|
|
# If no company in session or it doesn't exist, use the first company
|
|
|
|
|
company_id = Company.first&.id
|
|
|
|
|
session[:company_id] = company_id
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@company = Company.find(company_id) if company_id
|
2024-08-06 14:16:40 +02:00
|
|
|
end
|
2025-04-24 05:20:14 +00:00
|
|
|
|
|
|
|
|
def current_company
|
|
|
|
|
@company
|
|
|
|
|
end
|
|
|
|
|
helper_method :current_company
|
2024-08-04 07:06:03 +02:00
|
|
|
end
|