Tôi khá chắc chắn rằng lỗi không liên quan đến nội dung thực tế của TenantIdLoadermô-đun. Thay vào đó, nó có một cái gì đó để làm với ActiveSupportPhụ thuộc.
Tôi dường như không thể vượt qua lỗi này. Từ những gì tôi đã đọc, đó là bởi vì hoặc ActiveRecord::Baselà được tải lại hoặc Company::TenantIdLoaderđang được tải lại, và bằng cách nào đó nó không truyền đạt được điều đó. Giúp tôi với Tôi thực sự muốn có thể nâng cấp lên Rails 4.2.
BIÊN TẬP
Bây giờ tôi đã biết rằng đó là vì tôi đang tham khảo Tenantđang được tải lại tự động. Tôi cần phải có khả năng thực sự tham khảo lớp học, vậy có ai biết làm thế nào để khắc phục điều này không?
cấu hình / ứng dụng.rb
config.autoload_paths += %W( #{config.root}/lib/company )
cấu hình / khởi tạo / company.rb
ActionMailer::Base.send(:include, Company::TenantIdLoader)
lib / công ty / 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