title: Rails - redirection with locale
body: <p>I set the basic options for <code>locale</code> in <code>application.rb</code>:</p>
  
  <pre><code>config.i18n.available_locales = [:pl, :en]
  config.i18n.default_locale = :pl
  </code></pre>
  
  <p>And also scoped the routes:</p>
  
  <pre><code>Rails.application.routes.draw do
      get '/:locale', to: 'home#index'
      root            to: 'home#index'
  
      scope ":locale", locale: /#{I18n.available_locales.join("|")}/  do
        get 'settings', to: 'home#settings'
      end
  end
  </code></pre>
  
  <p>This way I can visit my root site under <code>www.mysite.com</code> and <code>www.mysite.com/en or pl</code>, as well as my settings site when including the locale in the url.</p>
  
  <p>Now let's say user typed <code>www.mysite.com/settings</code>. I want my app to know that there is no locale in the url, so go and grab the <code>default_locale</code>, set it, and redirect to <code>www.mysite.com/pl/settings</code>.</p>
  
  <p>How am I able to do it?</p>
  
  <p>PS I also have added those to my <code>ApplicationController</code>:</p>
  
  <pre><code>before_action :set_locale
  
      def set_locale
        I18n.locale = params[:locale] || I18n.default_locale
      end
  
      def default_url_options
        { locale: I18n.locale }
      end
  </code></pre>