Is there a way to set the locale and keep it set between requests without using a before_action/before_filter in the application controller?
I'm trying to avoid my current solution:
class ApplicationController < ActionController::Base
before_action :set_locale
def set_locale
I18n.locale = current_user.locale if current_user
end
end
class LocaleController < ApplicationController
skip_authorization_check
def index
locale = params[:locale]
raise 'Unsupported locale' unless ['en', 'pt'].include?(locale)
error_message = "Could not set locale" unless current_user.update_column(:locale, locale)
I18n.locale = current_user.locale if error_message.nil?
redirect_to :back, :alert => error_message
end
end