I am making a multi tenancy app using the apartment gem. I have it all set up and everything works as expected. I'm also using Rails Internationalization (I18n) with active record backend to store translations. My current setup
Translation Table
class CreateTranslations < ActiveRecord::Migration[5.0]
def change
create_table :translations do |t|
t.string :locale
t.string :key
t.text :value
t.text :interpolations
t.boolean :is_proc, default: false
t.timestamps
end
end
end
Apartment.rb configuration
I've added the Translation model to the list of excluded models so its global across all tenants
Apartment.configure do |config|
# Add any models that you do not want to be multi-tenanted, but remain in the global (public) namespace.
# A typical example would be a Customer or Tenant model that stores each Tenant's information.
#
config.excluded_models = %w{ User Workspace Translation }
end
In my translations table I have translations for both English (default) and Norwegian. On the main domain everything works as expected switching between English and Norwegian but all translations go missing once I load a tenant. Demo in console:
> Apartment::Tenant.switch! # switch to main tenant
> I18n.locale = :en # use English translations
> I18n.t('home.members_label')
=> "Show Members"
> Apartment::Tenant.switch! "elabs" # switch to a different tenant
> I18n.t('home.members_label')
=> "translation missing: en.home.members_label"
I'm not sure why translations are missing when in a tenanted environment. I was figuring having the Translation model in the list of excluded_models should do the trick but it seems something is wrong somewhere. Any clues? Thanks