【问题标题】:Apartment gem Custom Tenants Rails 5公寓 gem Custom Tenants Rails 5
【发布时间】:2018-05-11 02:26:05
【问题描述】:

我正在使用 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

如何将此帖子表添加到我选择的租户?

【问题讨论】:

    标签: ruby-on-rails postgresql rails-migrations apartment-gem


    【解决方案1】:

    据我了解,Apartement 不支持您的要求。

    如果您正在使用公寓开发 Rails 应用程序,您可能有一个变通办法。

    Loading tenant specific configurations(无耻抄自维基)

    #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']}"
    

    您可能会探索上述功能以根据租户隐藏/公开应用程序的租户特定区域。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多