A copy of xxx has been removed from the module tree but is still active
Tenant
is sort of a red herring - the error would occur if you referenced any bit of app that needs to be loaded by rails' const_missing
trick.
The problem is that you are taking something reloadable (your module) and then including it in something not reloadable (ActiveRecord::Base
or, in your earlier example ActionMailer::Base
). At some point your code is reloaded and now ActiveRecord still has this module included in it even though rails thinks it has unloaded it. The error occurs when you reference Tenant because that causes rails to run its const_missing
hooks to find out where Tenant should be loaded from and that code freaks out because the module where the constant search is starting from shouldn't be there.
There are 3 possible solutions:
Stop including your module into non reloadable classes - either include into individual models, controllers as needed or create an abstract base class and include the module in there.
Make this module non reloadable by storing it somewhere that isn't in autoload_paths (you'll have to require it explicitly since rails will no longer load it magically for you)
Changing Tenant to ::Tenant (
Object.const_missing
will then be invoked, notTenant.const_missing
)
ArgumentError (A copy of Api::V1 has been removed from the module tree but is still active!)
As the stack trace suggests, this is a dependancy clash of the app with ActiveSupport. I recommend using the gem bootsnap. Bootsnap overrides ActiveSupport::Dependencies
which is causing the issue in the first place. It also improves the app's load time which is actually what it is designed for. From Bootsnap documentation:
ActiveSupport::Dependencies.{autoloadable_module?,load_missing_constant,depend_on} are overridden to eliminate scans of ActiveSupport::Dependencies.autoload_paths.
A copy of XXX has been removed from the module but is still active
I don't think that provided error is somehow related to the code above.
Usually, this error happens when you modify your classes at runtime with metaprogramming.
Take a look at places where you require, define ExamResult
, it looks like you require it several times in your code.
A copy of ApplicationController has been removed from the module tree but is still active
This is a bug in Rails 2.3.3:
- https://rails.lighthouseapp.com/projects/8994/tickets/2948-exception-a-copy-of-actorscontroller-has-been-removed-from-the-module-tree-but-is-still-active
There is a patch for it (but incomplete?) in 2-3-stable:
- http://github.com/rails/rails/commit/d37ac7958fc88fdbf37a8948102f6b4e45c530b3
You have a few options to address the problem:
- Revert to Rails 2.3.2, wait for 2.3.4 to come out, probably at the end of August. 2.3.3 has a couple bad issues, so that might be best.
- The problem should not happen in production mode, nor will it happen in development mode under the Thin server. If you are having this issue on Google Engines in production mode, the patch is your only hope. If it's only in dev mode, you can just run your local server with Thin instead of Mongrel.
- If it is Google Engines, you can move off of Google Engines and host your app another way. This seems like a lot of work though.
Best of luck, this is a really bad bug many people are running into.
ArgumentError: A copy of ApplicationController has been removed from the module tree but is still active
I'm not sure exactly why this is happening, but I found a workaound. Change this:
def current_permission
@current_permission ||= Permissions.permission_for(current_user)
end
To this:
def current_permission
@current_permission ||= ::Permissions.permission_for(current_user)
end
The error is raised at this point in ActiveSupport:
# Load the constant named +const_name+ which is missing from +from_mod+. If
# it is not possible to load the constant into from_mod, try its parent
# module using +const_missing+.
def load_missing_constant(from_mod, const_name)
log_call from_mod, const_name
unless qualified_const_defined?(from_mod.name) && Inflector.constantize(from_mod.name).equal?(from_mod)
raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!"
end
# ...
end
The problem only occurs when you don't fully qualify the constant name, so Rails tries looking it up in the ApplicationController
namespace.
Rails reloading classes and 'has been removed from the module tree but is still active!' ArgumentError
The first approach looks cleaner -
Adding path where may 'FooBar::ControllerRuntimeis defined
toconfig.autoload_one_paths`
Reasons -
1) If you really wanna do some monkey patches in file like lib/extensions.rb, you may manually require it:
in config/initializers/require.rb:
require "#{Rails.root}/lib/extensions"
2) Follows proper naming conventions as you will have to list down the class and module .
I wouldn't suggest auto-loading for production application though , but if it's the last option than you can certainly try it out .
Good read here on the same - http://www.williambharding.com/blog/technology/rails-3-autoload-modules-and-classes-in-production/
Rails: A copy of MetricBase has been removed from the module tree but is still active
I'm still not sure what the original issue is/was. A workaround was to use zeus and kill and restart the server after an edit.
A better solution I am now using is putting the classes in a module Metrics
and it works.
Related Topics
Missing Symbol When Installing Ruby-2.3.0 on Os X 10.11.6 by Rvm
What's the Point of Unary Plus Operator in Ruby
How to Say Something Happened "X Minutes Ago" or "X Hours Ago" or "X Days Ago" in Ruby
Ruby 'Encode': "\Xc3" from Ascii-8Bit to Utf-8 (Encoding::Undefinedconversionerror)
Why Do I Get a Bcrypt-Ruby Gem Install Error
When Would a Ruby Flip-Flop Be Useful
3 Equals or Case Equality Operator
Split String into a List, But Keeping the Split Pattern
Google Maps, Ruby on Rails, Zoom Level with One Marker
Why Many People Use "-%>" Instead of "%>" in Rails
Variable Scope and Order of Parsing VS. Operations: Assignment in an "If"
Ruby on Rails Rmagick on Windows 7
Run Rspec Tasks in a Specific Order
What's the Point of Argv in Ruby
How to Generate a Human Readable Time Range Using Ruby on Rails