0

Apartment::Tenant.switch!("tenant_name")即使租户存在,我在执行时也会出错。

当我运行 Apartment::tenant_names 时,它返回一个包含数组,["murah5","rahmatullah","test"]然后我运行Apartment::Tenant.switch!("murah5")它返回:

Apartment::TenantNotFound: One of the following schema(s) is invalid: "murah5" "public" from /Users/fourtyonestudio/.rvm/gems/ruby-2.4.1/gems/apartment-1.2.0/lib/apartment/adapters/postgresql_adapter.rb:72:in在 connect_to_new 中救援'`

你能帮我处理这个案子吗?

4

2 回答 2

1

此错误可能是由于数据库中缺少该名称的架构

https://dba.stackexchange.com/questions/40045/how-do-i-list-all-schemas-in-postgresql

于 2017-12-01T04:11:15.637 回答
0

您可以在模型中创建一个方法(创建租户)

     class Tenant < ApplicationRecord
       def self.switch(subdomain)
         Apartment::Tenant.switch! subdomain
       end
     end

然后你可以从 Rails 控制台切换你的子域,比如

  Tenant.switch('app')

通过以下方式检查您当前的子域Apartment::Tenant.current

于 2017-11-20T02:00:28.417 回答