使用Apartment Gem切换租户时出错

时间:2017-08-15 07:39:15

标签: ruby-on-rails rubygems multi-tenant apartment-gem apartments

即使租户存在,我也会在执行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'`

你可以帮我解决这个案子吗?

2 个答案:

答案 0 :(得分:0)

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

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

然后您可以从rails控制台切换子域名,如

  Tenant.switch('app')

Apartment::Tenant.current

检查您当前的子域名

答案 1 :(得分:0)

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

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