title: Ruby on Rails: how to design a SaaS infrastructure?
body: <p>I'm building a Rails 3 application that I plan on provided as a subscription-based SaaS (Software as a Service) product.  Basically, I want users to be able to hit my "Sign up" page, create a new account, and immediately start using the software.</p>
  
  <p>A good example of what I'm trying to accomplish is: <a href="http://www.getharvest.com/" rel="noreferrer">http://www.getharvest.com/</a></p>
  
  <p>Here's what I need to happen when someone signs up:</p>
  
  <ol>
  <li>A MySQL database for them is generated on the db server</li>
  <li>A sub-domain is created (e.g., companyx.awesomeapp.com)</li>
  <li>The Rails app should know the appropriate database to connect to based on the sub-domain</li>
  </ol>
  
  <p>Are there any good guides out there for setting this stuff up?  Even better, are there services that you can purchase to automate this type of thing?  Ideally, I'd like to just worry about writing my Rails app and then be able to plop it atop some awesome Rails SaaS infrastructure.</p>
  
  <p>(Also, I need a way to bill them monthly, but I think that's a separate question/problem.)</p>