我很确定这个错误与TenantIdLoader
模块的实际内容无关.相反,它与ActiveSupport
个依赖项有关.
我似乎无法克服这个错误.从我所读到的,这是因为要么ActiveRecord::Base
正在被重新加载,要么Company::TenantIdLoader
正在被重新加载,而它不知何故没有传达这一点.救命啊!我真的很想升级到Rails 4.2.
EDIT
我现在明白了,这是因为我正在引用Tenant
,它会自动重新加载.但我需要能够实际引用这个类,所以有人知道如何避开这个问题吗?
配置/应用程序.rb
config.autoload_paths += %W( #{config.root}/lib/company )
配置/初始化者/公司.rb
ActionMailer::Base.send(:include, Company::TenantIdLoader)
租户/加载器公司.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