title: rails get app root/base url
body: <p>In my app I have a few APIs that under api domain.  Now in one of the API I want to generate a url that pointing to the main domain, say</p>
  
  <pre><code>test.com/blabla...
  </code></pre>
  
  <p>I tried to use  <strong>url_for</strong> but seems the default <strong>root_url</strong> or <strong>request.host</strong> is in api domain. Url_for will make it to be</p>
  
  <pre><code>api.test.com/blabla..
  </code></pre>
  
  <p>while I want it to be </p>
  
  <pre><code>test.com/blabla...
  </code></pre>
  
  <p>Url_for can take a parameter</p>
  
  <pre><code>host: ...
  </code></pre>
  
  <p>to set it to be test.com/, the question is how can I get the root/base url (test.com) for host?  <strong>root_url</strong> or <strong>request.host</strong> are all api.test.com.</p>
  
  <p>Any ideas? Thanks.</p>