title: Rails Basecamp style subdomains best practice
body: <p>My goal is to have separate user accounts for each subdomain.  Under no circumstance do I want cross-pollination between subdomains.</p>
  
  <p>I've looked over <a href="http://www.robbyonrails.com/articles/2009/01/11/subdomain-accounts-with-ruby-on-rails-explained" rel="nofollow">Robby Russle</a>, and <a href="http://37signals.com/svn/posts/1512-how-to-do-basecamp-style-subdomains-in-rails" rel="nofollow">DHH's</a> thoughts (both are pre-Rails3 though).</p>
  
  <p>The controller handling is pretty straight forward, my questions is about keeping the model's data separated.  What's the best way to keep user1 from seeing user2's data?</p>
  
  <p>Some idea's might include:</p>
  
  <ol>
  <li><p>Add a <code>subdomain_id</code> foreign key to every model - <em>Advantage</em>, simple one-to-many relationship can be used to scope each model to a subdomain. - <em>Disadvantage</em>, this is pretty tight coupling between the data and the larger application logic, which seems inappropriate.</p></li>
  <li><p><code>One-to-many :through</code> for each model associating it with a subdomain - <em>Advantage</em>, no need to add a <code>subdomain_id</code> foreign key column to existing tables associating them with their sub domain.  - <em>Disadvantage</em>, My gut feeling is that this is way overkill.  Multiple join queries may get complicated and cross-pollination bugs may occur.</p></li>
  <li><p>Separate applications or databases for each subdomain - <em>Advantage</em>, the data is completely segregated. - <em>Disadvantage</em>, a large number of individual applications/databases will need to be managed/updated/secured/hosted/etc.</p></li>
  <li><p>Your idea?</p></li>
  </ol>