Topic: Provisioning of applications for multiple clients

I'm interested in the theory behind setting up multiple instances of an application.

Similar to Basecamp; when you sign up for an account, it creates an instance of the basecamp project management tool for a company at a specified url such as companyname.updatelog.com

How is this done?
Does is recreate a rails folder structure at companyname.updatelog.com?
Is is done in the application or database?

Any information on how this can be intergrated into an exsiting application so that I can have multiple instances of my app for each client would be appreciated.

thanks

Cheers

Craig

Last edited by ccherlet (2006-11-08 18:23:08)

Re: Provisioning of applications for multiple clients

Hi Craig,

All of this can be easily done using a  before_filter as part of your ApplicationController (application.rb).

You can either roll your own, or use something like the account_location plugin.

If you decide to roll your own, just create a before_filter that locates the account based on the subdomain.  The subdomain could be the username of the account, or an optional field the user enters when creating an account.

Here's a small snippet that may help you:

def account_as_subdomain
  @account = Account.find_by_subdomain(self.request.subdomains.first)

  render :file => "#{RAILS_ROOT}/public/account_not_found.html", :layout => false, :status => 404 and return false unless @account
end


From that point forward, you have access to an instance variable @account in all of your controllers.  Reference and look for other models using a syntax like:  @account.projects, and you'll find that you now have automatic scoping.  @account.projects will only find projects for that account!

As far as theory goes, everything is stored in the same database for all of the clients.  There is only one application serving all of the requests.

Ruby Rockstars - Ruby Jobs for all!

Re: Provisioning of applications for multiple clients

Wicked!

Thank you so much for your insight.
Makes alot of sense.

Cheers

Craig