-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ArgumentError: A copy of ApplicationController has been removed from the module tree but is still active #2334
Comments
Some historical links, since none of the Google hits are for anything but Rails 2: |
I think unloadable has been deprecated. When I check the list of Autoloaded constants in dependencies.rb, the array does not have activeadmin generated controllers in it. Could this be the problem? By default, all directories under app are in the autoload path. Not sure if I should add something explicitly to mark these controllers as autoload, or how to go about doing it. |
Does this occur if you create a brand new app on Rails 4 with AA? |
Yep. You can check this project to simulate the problem: https://github.com/highnotes/eardrums Start up rails and guard, and change something in the app/admin/* files. You should start getting the above exception after that. |
Thanks for the project; I'll try and look into this today. |
I'm getting hit with this too. Rails 4.0.0 and the rails4 branch of active admin. I realize this comment doesn't help much, but so far my hunches indicate it has something to do with having devise on both a frontend and a backend with different user models.. before I started using devise on the frontend for authentication, I never ran into this issue.
|
@stereoscott can you provide more details? @subhashb 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
# ... The problem only occurs when you don't fully qualify the constant name, so Rails tries looking it up in the |
Yep, that solved the problem! And you are right, seems to be a problem with looking up the constant under a different namespace. |
Cool. Could you mark your SO question as answered? |
Marked as answered and Accepted! Muchas Gracias! |
This doesn't seem closed to me. I also see this and am able to work around it by adding the absolute namespace qualification somewhat randomly to things in my application controller. Trouble is that's not very self-documenting and there seemingly isn't much rhyme or reason to where its needed. |
Unfortunately you're right @derekprior. This is likely to be the cause: #2329 (comment). I've been quite busy lately so haven't revisited that. Hopefully I'll get to it soon. If you want, you could try ensuring that |
Hi Daxter - what's the recommended way to prevent ActiveAdmin from adding itself to the load path? |
Do you mean in reference to my comment yesterday? And just to clarify, AA doesn't add itself to the load path, Rails does it automatically for any folder inside of the |
I've got an app where I've got some classes in app/models (not ActiveRecord) like sidenav.rb (class Sidenav; end) If I don't put ::Sidenav in ApplicationController, every now and then I'll get this error ("A copy of ApplicationController has been removed from the module tree but is still active"). It appears that it's related to this but I'm not quite sure how. Should I reject!( app/admin ) from the eager_load_path in the config? |
@davidyang can you try out #2484? |
Still got it with rails 4.0.1 and activeadmin (master branch). It happens all the time for me. |
@thehappycoder can you try isolating the problem code so we have something to work from? |
To reproduce I just had to:
It started to work fine when I commented the before_action class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :authenticate_user!
#before_action :load_common
after_action :disable_cache_for_xhr
helper_method :ip_banned?
protected
def authenticate_admin_user!
redirect_to(new_user_session_path) unless current_user.try(:admin?)
end
def load_common
@common_presenter = CommonPresenter.new
end
def ip_banned?(request)
BannedContact.ip_banned?(request.remote_ip)
end
def cities_settings(request)
cities_settings_json = request.cookies['cities_settings']
if cities_settings_json
JSON.parse(cities_settings_json)
else
{}
end
end
def disable_cache_for_xhr
if request.xhr?
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end
true
end
end If it happens again, I will let you know. |
@thehappycoder Can you try fully qualifying the constant name, like so ::CommonPresenter.new in load_common? |
::CommonPresenter.new solves the problem |
Yeah, that's the workaround I found too. Otherwise, AA seems to be trying to lookup the constant in a different namespace. |
I have the following method in application_controller.rb
But I get the following error: ArgumentError in Admin::DashboardController#index On line: @current_user ||= ::User.find_by_auth_token(cookies[:auth_token]) if cookies[:auth_token] This is with the 1.0.0-pre gem. |
I'm getting this error now. I need to restart the rails server in order to work every time I change something in a file inside app/admin |
@Ricardonacif can you post a stack trace? |
Thanks @subhashb for the workaround. Would be great to have this fixed – we restarted the server hundreds of times before starting looking for this. x) |
We also had this problem and fully qualifying our objects in the ApplicationController was the trick. So, to be clear, I looked for any of our specific models and preceded with Example: |
Fully qualifying all constants solved the issue for: Rails 4.1.15 // ActiveAdmin 1.0.0.pre2 Example: |
I'm still getting the circular dependency issue with Rails 4.2.7 and latest ActiveAdmin from git Coming from an older version I recall all models were plural, but now it seems they are singular? What's interesting is this issue only exists when requiring the Rails environment from an external script, e.g.
|
We're experiencing similar issues with things like |
This happens on Rails 5.0.0.1 as well -- whenever the code changes. If I don't change any code, I don't have to restart the server. |
Prefixing |
Prefixing all the contants in our |
Interesting that this was reported shortly after d7a3ea9 |
Yeah, it's likely a bug in how Rails auto-loads files. In particular, that commit made it so the file names for models and AA config files are identical. |
I am using
I did that @jtomaszewski suggested and renamed I'd suggest to re-open this issue. |
If people are still encountering this (like I am with Rails 5.1.4 and ActiveAdmin 1.1.0) and coming to this ticket from google, you can fix this without renaming or fully qualifying classes. Just exclude app/admin from the eager loaded (or auto loaded) paths. It looks something like this: config.eager_load_paths = Dir.glob("#{Rails.root}/app/*").reject do |path|
path.include?("admin")
end From here: http://guides.rubyonrails.org/configuring.html.
|
Hello, everyone. I have the same problem as i thought in issues
Rails v 5.1.4, Ruby v 2.3.1p112, ActiveAdmin 1.1.0 I tried to rename "app/admin/admin_user.rb" but nothing happen. |
Prepending |
I found out the issue was that It looks like we need to add mechanism to InheritedResources gem (also owned by ActiveAdmin) to do reloading correctly.
ActiveAdmin reloaded the classes correctly in here activeadmin/lib/active_admin/application.rb Line 190 in e0ac14d
|
When I dig into this further, it turns out that ActiveAdmin's own controllers are also not reloaded properly. It is this whole tree that need to be unload & reloaded. I've attempted to do that manually in my app without success. ActiveAdmin::ResourceController < ActiveAdmin::BaseController < InheritedResources::Base Still have to rely on the hack in this issue to work-around it. |
Prefixing all the constants in our rails 5.2.1 |
I am using the latest master, with Rails: 4.0.0.rc2
I experience the above exception, only when I change something in admin/*.rb files, and try to refresh the view.
The entire gist of the problem is here: Stackoverflow 17561697
I think this is related to ActiveAdmin + InheritedResources generated controllers "not being" in the autoload path of Rails, but I might be wrong.
Not sure if this is related to #697 either.
Is there a way to circumvent the problem?
The text was updated successfully, but these errors were encountered: