相关疑难解决方法(0)

xxx的副本已从模块树中删除但仍处于活动状态

我很确定错误与TenantIdLoader模块的实际内容无关.相反,它与ActiveSupport依赖关系有关.

我似乎无法克服这个错误.从我读过的内容来看,这是因为要么ActiveRecord::Base正在重新Company::TenantIdLoader加载,要么正在重新加载,而且它在某种程度上没有进行通信.请帮忙!我真的希望能够升级到Rails 4.2.

编辑

我现在已经知道这是因为我正在引用Tenant哪些是自动重新加载的.我需要能够实际引用该课程,所以有人知道如何解决这个问题吗?

配置/ application.rb中

config.autoload_paths += %W( #{config.root}/lib/company )
Run Code Online (Sandbox Code Playgroud)

配置/初始化/ company.rb

ActionMailer::Base.send(:include, Company::TenantIdLoader)
Run Code Online (Sandbox Code Playgroud)

LIB /公司/ 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] ||= …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails ruby-on-rails-4

118
推荐指数
3
解决办法
4万
查看次数

标签 统计

ruby ×1

ruby-on-rails ×1

ruby-on-rails-4 ×1