title: Add a prefix to generated links, but not to incoming routes
body: <p>Our Rails 4 application needs to be accessible over an archaic portal. This portal works by adding (from the perspective of the browser) a prefix to each URL; this prefix is removed by the portal before forwarding the request to my application.</p>
  
  <p>So the browser calls <code>https://portal.company.com/portal/prefix/xyzzy/myapp/mymodel/new</code>; the portal does its thing and requests <code>https://myserver.company.com/myapp/mymodel/new</code> (passing along the stripped prefix in some irrelevant way). The prefix is dynamic and can change between requests.</p>
  
  <p>The problem is that the portal is not able to rewrite the HTML pages served by my application. That is, it does not put in the prefix. It expects applications to either only emit relative URLs, or to add the portal prefix themselves.</p>
  
  <p>So:</p>
  
  <ul>
  <li>A regular URL <code>/myapp/mymodel/new</code>, for example, must stay as is for when the application is accessed directly (for certain users which do not use the portal).</li>
  <li>When accessed over the portal, our application must still understand <code>/myapp/mymodel/new</code> as usual, but when using <code>mymodel_new_path</code> or <code>link_to @mymodel</code> or <code>form_for @my_model</code> or whatever other magic URL generators there are, it has to add the portal prefix. So, any URL emitted by the application must look like <code>/portal/prefix/xyzzy/myapp/mymodel/new</code> where the per-request string <code>/portal/prefix/xyzzy</code> is given by some method defined by us (and the part <code>xyzzy</code> can change between requests).</li>
  </ul>
  
  <p>How can I achieve that? My <code>routes.rb</code> looks like this today:</p>
  
  <pre><code>MyApp::application.routes.draw do
    scope ' /myapp' do
      get ...
  </code></pre>
  
  <p>This probably has to stay as is, because URLs in incoming requests do not change when coming from the portal. But how do I influence the outgoing URLs?</p>