title: Forcing Subdomains and Removing Subdomains
body: <p>I am writing an app that will use basecamp style subdomains (<a href="http://37signals.com/svn/posts/1512-how-to-do-basecamp-style-subdomains-in-rails" rel="nofollow">See post</a>).</p>
  
  <p>There are portions of the app that should <strong>always be in a subdomain</strong> and portions that should <strong>never be in a subdomain</strong>.  For example, the "home" page should never be in a subdomain, but the blogs and posts resources always should.  Keep in mind, I don't know the subdomains, as there is one per account.</p>
  
  <p>I set up my routes like this (example).  It works well in that it matches the routes, but I am having difficulty forcing my app to link to the correct locations.</p>
  
  <pre><code>MyApp::Application.routes.draw do
  
    # these should all route to mysubdomain.myapp.com
    # Clicking on a post from myapp.com/categories/12 should take you to mysubdomain.myapp.com/posts/14
    constraints(Subdomain) do
      resources :blogs { resources :posts }
    end
  
    # these should all route to myapp.com (clicking on one of these links from mysubdomain.myapp.com should go to myapp.com/categories/12)
    constraints(NoSubDomain) do
      resources :categories
    end
  
  end
  </code></pre>
  
  <p>The problem is that once I am in a subdomain, all of the links to the other pages (categories, etc) contain the subdomain.  I am not sure the best to solve this issue.  Thank you so much for your help.</p>