title: Setting the locale at runtime just once in Rails
body: <p>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?</p>
  
  <p>I'm trying to avoid my current solution:</p>
  
  <pre><code>class ApplicationController &lt; ActionController::Base
    before_action :set_locale
  
    def set_locale
      I18n.locale = current_user.locale if current_user
    end  
  end
  
  class LocaleController &lt; 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 =&gt; error_message
    end
  end
  </code></pre>