![](/img/trans.png)
[英]Rails 5 - How to have shared data across multiple tenants in apartment gem?
[英]Apartment gem Custom Tenants Rails 5
我正在使用Apartment gem構建多租戶應用程序。 我擁有所有租戶將共有的核心功能。 但是現在我想為TenantB添加一個表,該表將不在TenantA的模式中。 如果我執行以下操作,它將表添加到有能力的租戶。
class CreateStickies < ActiveRecord::Migration[5.0]
def change
if table_exists? :tenantb
create_table :post do |t|
t.text :body
t.string :title
t.timestamps
end
end
end
end
如何將此Posts表添加到我選擇的租戶中?
據我了解, Apartement
不支持您的要求。
如果您正在使用公寓開發Rails應用程序,則可能需要解決。
加載租戶特定的配置 (從Wiki中無恥地復制)
#config/initializers/country_specific.rb
COUNTRY_CONFIGS = YAML.load_file(Rails.root.join('config', 'country_specific' , 'config.yml'))
#config/country_specific/config.yml
da:
site_name: Boligsurf.dk
se:
site_name: Bostadssurf.se
#app/controllers/application_controller
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_country_config
......
def set_country_config
$COUNTRY_CONFIG = COUNTRY_CONFIGS['da'] #As default as some strange domains also refer this site, we'll just catch em as danish
$COUNTRY_CONFIG = COUNTRY_CONFIGS['se'] if request.host.include? 'bostadssurf'
end
#Somewhere in your code
puts "Welcome to #{$COUNTRY_CONFIG['site_name']}"
可能您可能會探索上述功能,以根據租戶隱藏/公開應用程序中特定於租戶的區域。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.