I am implementing a multitenant RoR application. Tenants are identified using the first segment in the path as the tenant identifier instead of subdomains. My understanding is that getsatisfaction.com implements this kind of multitenant routng. Ex:
http://myapp.com/tenant1/resource instead of http://tenant1.myapp.com, http://tenant2.myapp.com
I am looking to implement the following routing behaviour
get the tenant part from myapp.com/segement1/resource
if [segment1] has an entry in our db as a tenant
then set base_url as [http://myapp.com/segment1], and do the route lookup for /resource
else
set base_url as [http://myapp.com/] and do the route lookup for /segment1/resource
To illustrate
http://myapp.com/login will not match any tenant, hence will login to the site
http://myapp.com/org1/tasks will match a tenant named org1, get the 'tasks' of org1
http://myapp.com/tasks will not many any tenant, get the task of all orgs
I tried reading up RoR routes.rb, url rewrite, apache but unable to figure out the best way to do this. Any pointers on how to implement this?