我相信错误与TenantIdLoader
模块的实际内容无关。 相反,它与ActiveSupport
Dependencies有关。
我似乎无法解决这个错误。 根据我所了解的,这是因为要么重新加载了ActiveRecord :: Base
,要么重新加载了Company :: TenantIdLoader
,而且它在某种程度上没有得到通信。 求助!我真的很想升级到Rails 4.2。
编辑
我现在知道这是因为我正在引用自动重新加载的Tenant
。但我仍然需要能够实际引用该类,那么有谁知道如何解决这个问题吗?
config/application.rb
config.autoload_paths += %W( #{config.root}/lib/company )
config/initializers/company.rb
ActionMailer::Base.send(:include, Company::TenantIdLoader)
lib/company/tenant_id_loader.rb
module Company
module TenantIdLoader
extend ActiveSupport::Concern
included do
cattr_accessor :tenant_dependency
self.tenant_dependency = {}
after_initialize do
self.tenant_id = Tenant.active.id if self.class.tenant_dependent? and self.new_record? and Tenant.active.present? and !Tenant.active.zero?
end
end
# class methods to be mixed in
module ClassMethods
# returns true if this model's table has a tenant_id
def tenant_dependent?
self.tenant_dependency[self.table_name] ||= self.column_names.include?('tenant_id')
end
end
end
end