ruby on rails - A copy of xxx has been removed from the module tree but is still active -
i'm pretty sure error has nothing actual content of tenantidloader module. instead has activesupport dependencies.
i can't seem past error. i've read, it's because either activerecord::base getting reloaded or company::tenantidloader getting reloaded, , it's somehow not communicating that. please! i'd able upgraded rails 4.2.
edit
i've learned it's because i'm referencing tenant getting reloaded automatically. need able reference class though, know how around this?
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 cattr_accessor :tenant_dependency self.tenant_dependency = {} after_initialize self.tenant_id = tenant.active.id if self.class.tenant_dependent? , self.new_record? , tenant.active.present? , !tenant.active.zero? end end # class methods mixed in module classmethods # returns true if model's table has tenant_id def tenant_dependent? self.tenant_dependency[self.table_name] ||= self.column_names.include?('tenant_id') end end end end
tenant
sort of red herring - error occur if referenced bit of app needs loaded rails' const_missing
trick.
the problem taking reloadable (your module) , including in not reloadable (activerecord::base
or, in earlier example actionmailer::base
). @ point code reloaded , activerecord still has module included in though rails thinks has unloaded it. error occurs when reference tenant because causes rails run const_missing
hooks find out tenant should loaded , code freaks out because module constant search starting shouldn't there.
there 3 possible solutions:
stop including module non reloadable classes - either include individual models, controllers needed or create abstract base class , include module in there.
make module non reloadable storing somewhere isn't in autoload_paths (you'll have require explicitly since rails no longer load magically you)
changing tenant ::tenant (
object.const_missing
invoked, nottenant.const_missing
)
Comments
Post a Comment