即使租户存在,我也会在执行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'`
答案 0 :(得分:0)
你可以在模型中创建一个方法(创建租户)
class Tenant < ApplicationRecord
def self.switch(subdomain)
Apartment::Tenant.switch! subdomain
end
end
然后您可以从rails控制台切换子域名,如
Tenant.switch('app')
按Apartment::Tenant.current
答案 1 :(得分:0)