Skip to content

Multi sites app

Petr Mlčoch edited this page Aug 15, 2022 · 1 revision

Setup

  • create many Folio::Sites, domain should include www.
  • change Folio config to config.folio_site_is_a_singleton = false
  • override Folio.current_site, eg:
    module Folio
      def self.current_site(request: nil)
        if Rails.application.config.folio_site_is_a_singleton
          Folio::Site.instance
        else
          raise "request is needed to find correct site" if request.nil?
          Folio::Site.find_by(domain: request.host)
        end
      end
    end
    
  • models related to site needs column site_id and include Folio::BelongsToSite

Usage

  • in app, current_site helper returns value of site from request (in controller/view)
  • in test, use helper create_and_host_site(key: site_key, attributes: {}). site_key is name of specific factory. If it is not present Rails.application.config.folio_site_default_test_factory || :folio_site are used.