title: Rails mountable engine under a dynamic scope
body: <p>say that I have these routes:</p>
  
  <pre><code>scope '(:locale)', :locale =&gt; /en|de/ do
    mount Users::Engine =&gt; "users", as: 'users_engine'  
  end
  </code></pre>
  
  <p>and in engine's view:</p>
  
  <pre><code>&lt;%= link_to 'new user', action: :new, controller: :users, locale: :de %&gt;
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>/en/users/users/new?locale=de 
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>/de/users/users/new
  </code></pre>
  
  <p>I have already included in application controller:</p>
  
  <pre><code>def set_locale
    if params.include?('locale')
      I18n.locale = params[:locale]
      Rails.application.routes.default_url_options[:locale] = I18n.locale
    end
  end
  </code></pre>
  
  <p>and it works fine in the main app</p>
  
  <p>I have found a way to get the right url by </p>
  
  <pre><code>Users::Engine.routes.url_for controller: 'users/users', action: :new, only_path: true, locale: :de
  </code></pre>
  
  <p>but I think that there should be a better way and what if I was making a change-locale link in the layout ?</p>
  
  <pre><code>&lt;%= link_to locale: :de %&gt;
  </code></pre>
  
  <p>I cannot know which exact engine this could be</p>
  
  <p>Thanks vm.</p>