我正在實施多租戶RoR應用程序。租戶使用路徑中的第一個段作爲租戶標識符而不是子域標識。我的理解是,getsatisfaction.com實現這種多租戶行爲。例如:基於路徑的多租戶RoR應用程序的URL路由
http://myapp.com/tenant1/resource代替http://tenant1.myapp.com,http://tenant2.myapp.com
我期待實現以下路由行爲
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
爲了說明
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
我試着讀了回報率的routes.rb,網址重寫,阿帕奇,但無法找出最好的方式來做到這一點。任何關於如何實現這一點的指針?
您是否得到了針對您問題的通用解決方案?我面臨同樣的問題,並希望避免子域以及 – scanales 2013-03-05 00:06:32