gpt4 book ai didi

ruby-on-rails - 基于路径的 Multi-Tenancy RoR 应用程序 URL 路由

转载 作者:行者123 更新时间:2023-12-04 05:44:52 25 4
gpt4 key购买 nike

我正在实现 Multi-Tenancy RoR 应用程序。使用路径中的第一段作为租户标识符而不是子域来标识租户。我的理解是 getsatisfaction.com 实现了这种 Multi-Tenancy 路由。例如:

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

我尝试阅读 RoR routes.rb、url rewrite、apache,但无法找到执行此操作的最佳方法。关于如何实现这个的任何指示?

最佳答案

您可以尝试确定一些路线的范围:

resources :tasks

scope ':tenant' do
root to: 'dashboard#index', as: 'dashboard'
resources :tasks
end

在您的 TasksController 中,您将获得一个 param[:tenant] 变量,您可以使用它来查找租户。如果 param[:tenant] 为 nil,则可以直接返回所有任务。

关于ruby-on-rails - 基于路径的 Multi-Tenancy RoR 应用程序 URL 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9140344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com