title: Multiple users with single database Ruby on Rails 4
body: <p>I'm building a system that (when completed) will serve multiple commercial customers. I need to accomplish the following:</p>
  
  <ol>
  <li>App should use one database</li>
  <li>Each commercial customer will have multiple users.</li>
  <li>When any of the commercial customer's users create/read data, they should do so under the commercial customer's namespace....Thus they should not be able to see other customers' data and should also not be allowed to create data etc. for other customers.</li>
  </ol>
  
  <p>Initially I thought that the best way would be to assign all users to a commercial customer via association. As I was worried about querying the database too much, I did some research and found some info regarding Rack and middleware. This seems to be another option of achieving what I want, but it confused me a little.</p>
  
  <p>What is the best option to achieve this sort of functionality in my app?</p>
  
  <p>**PS. All commercial Customers will have unique URL's ex. customer1.myapp.com</p>
  
  <p>Thanks</p>