【发布时间】:2015-06-20 14:15:11
【问题描述】:
我很确定该错误与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
【问题讨论】:
-
这个答案有帮助吗? stackoverflow.com/questions/17561697/…
-
您确定涉及到租户类吗?如果您将使用 Tenant 的代码部分剔除,您还会收到错误吗?
-
@WaynnLue 是的,我认为这就是原因,我只是不知道如何解决它。
-
@FrederickCheung 我有另一个与此类似的文件,它以同样的方式出错,并且总是在与租户相关的行上出错,所以这是我最好的猜测。
-
虽然您在这里没有在 Rails 中使用 Wisper,但如果您不遵循此线程中的建议,其他人可能会注意到 Wisper 相当一致地导致此问题:stackoverflow.com/questions/28346609/…跨度>
标签: ruby-on-rails ruby ruby-on-rails-4