Activeadmin: ArgumentError: A copy of ApplicationController has been removed from the module tree but is still active

Created on 10 Jul 2013  Â·  60Comments  Â·  Source: activeadmin/activeadmin

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?

class reloading

Most helpful comment

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.

All 60 comments

I think unloadable has been deprecated.
The solution may lie in making Controllers generated by inherited_resources autoloadable.

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.

#Gemfile.lock
remote: git://github.com/gregbell/active_admin.git
  revision: 72a9c30cef47b3f38c38039de021aaa3194c188b
  branch: rails4

@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 ApplicationController namespace.

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: https://github.com/gregbell/active_admin/issues/2329#issuecomment-21824069. 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 app/admin isn't in your eager_load_paths. If it is currently, and the problem goes away when you remove it, then the solution is clear.

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 app directory.

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:

  1. Load rails app
  2. Log in as admin (devise) or be already logged in
  3. Load active admin page
  4. Change DSL for that page
  5. Reload page
  6. Get ArgumentError: A copy of ApplicationController has been removed from the module tree but is still active inside "load_common" method, first line

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

def current_user
  if Rails.env.test?
    @current_user ||= ::User.find(session[:user_id]) if session[:user_id]
  else
    @current_user ||= ::User.find_by_auth_token(cookies[:auth_token]) if cookies[:auth_token]
  end
end

But I get the following error:

ArgumentError in Admin::DashboardController#index
A copy of ApplicationController has been removed from the module tree but is still active!

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?

Sure!

A copy of ApplicationController has been removed from the module tree but is still active!

activesupport (4.0.0) lib/active_support/dependencies.rb:445:in `load_missing_constant'
activesupport (4.0.0) lib/active_support/dependencies.rb:183:in `const_missing'
app/controllers/application_controller.rb:14:in `load_footer_variables'
activesupport (4.0.0) lib/active_support/callbacks.rb:377:in `_run__1837454153976331159__process_action__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__1434760365269972130__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/Users/ricardonacif/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/Users/ricardonacif/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/Users/ricardonacif/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

Try to add config.skip_before_filter :load_footer_variables in config/initializers/active_admin.rb. load_footer_variables is before_filter defined in application.rb, right?

FWIW I encountered the error in #2990 "Circular dependency detected while autoloading constant AdminUser". In my case I had app/admin/admin_user.rb which ActiveAdmin.register AdminUser do.... I also have of course app/models/admin_user.rb.

Changing the file name (just the filename) to app/admin/admin_user.rb resolved my issue. No other changes were made anywhere.

Just wanted to get this in for the archives...

Changing the file name (just the filename) to app/admin/admin_user.rb resolved my issue.

I don't understand, what part of the file name did you change?

I changed app/admin/admin_user.rb to app/admin/admin_users.rb

-- Philip

On May 8, 2014, at 6:19 PM, Sean Linsley [email protected] wrote:

Changing the file name (just the filename) to app/admin/admin_user.rb resolved my issue.

I don't understand, what part of the file name did you change?

—
Reply to this email directly or view it on GitHub.

I'm having the same issue here (rails 4.1.1, activeadmin branch master):

activesupport-4.1.2/lib/active_support/dependencies.rb:478:in `load_missing_constant': Circular dependency detected while autoloading constant AdminUser (RuntimeError)

Renaming the files in app/admin/* solved it as mentioned by @phallstrom

Same issue on rails 4.1.1 and gem 'activeadmin', github: 'gregbell/active_admin'

Need to apply :: for any class in my application_controller.rb, that solves this

Another person reported this issue in IRC

Refering to every constant with prefix "::" solves this problem for me.

Would it be wrong to suggest that the resource generator uses a pluralized version of the model for the filename? @phallstrom's solution seems to be the simplest.

same issue in Rails 4.1.5

I'm seeing this too, but only on my dashboard. Navigating to a resource page, eg /admin/users works

I've got mine working. I'm not totally sure why, however here are things that seemed to make a difference:

  • In a panel, I was using class methods on a class that was not ActiveRecord. Moving those class methods to an ActiveRecord class made it work
  • I had a class Stats, but postgres also has a Stats class. This coincides with what some are reporting about using ::Class. The rest of my app referenced my Stats local to the app no problem. Perhaps ActiveAdmin can't order these correctly and picks the wrong one? And as a result of that, methods, initializers, class variables are applied to the wrong class. (These exceptions will be hidden)
  • Getting an (honest) error referencing the class, like say calling an undefined method, or having an exception (like an incompatible cast from string to int) was hidden and showed up as this strange ActionController message.

key point
Test whatever interpolations or class/method references in rails console or something. An exeption in your classes will be hidden by activeadmin and show up as this ActionController problem.

I believe this exception is raised any time you are trying to an access a class that is automatically reloaded in the dev environment from a file that is not automatically reloaded (like from a gem or your lib directory). More discussion around that here: http://stackoverflow.com/a/23008837/149503

hmm. My class is in app/services, which I think is reloaded

Fully qualifying all constants in our app's ApplicationController fixed this issue for us.

Rails 4.2 with ActiveAdmin 1.0.0.pre1.

I get this on Rails 4.2 with ActiveAdmin 1.0.0.pre1 but with ApplicationHelper rather than ApplicationController

fully qualifying the constant name, like so ::CommonPresenter.new

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:
A reference to UserSession was updated to ::UserSession

Fully qualifying all constants solved the issue for: Rails 4.1.15 // ActiveAdmin 1.0.0.pre2

Example:
A reference to UserSession was updated to ::UserSession

I'm still getting the circular dependency issue with Rails 4.2.7 and latest ActiveAdmin from git
After doing a fresh install, the generator adds app/admin/admin_user.rb, but seems to conflict with app/models/admin_user.rb

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. require_relative 'config/environment' and does not show up when running standard rails s

RuntimeError: Circular dependency detected while autoloading constant AdminUser
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:492:in `load_missing_constant'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:184:in `const_missing'
    from /Users/michael/Development/pingzapper-site/app/admin/admin_user.rb:1:in `<top (required)>'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:457:in `load'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:457:in `block in load_file'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:647:in `new_constants_in'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:456:in `load_file'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:354:in `require_or_load'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:494:in `load_missing_constant'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:184:in `const_missing'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/inflector/methods.rb:261:in `const_get'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/inflector/methods.rb:261:in `block in constantize'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/inflector/methods.rb:259:in `each'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/inflector/methods.rb:259:in `inject'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/inflector/methods.rb:259:in `constantize'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:566:in `get'
... 48 levels...
    from (irb):1
    from /Users/michael/.rbenv/versions/2.3.1/bin/irb:11:in `<top (required)>'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `load'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `kernel_load'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:24:in `run'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli.rb:304:in `exec'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli.rb:11:in `start'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/exe/bundle:27:in `block in <top (required)>'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
    from /Users/michael/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/exe/bundle:19:in `<top (required)>'
    from /Users/michael/.rbenv/versions/2.3.1/bin/bundle:23:in `load'
    from /Users/michael/.rbenv/versions/2.3.1/bin/bundle:23:in `<main>'

We're experiencing similar issues with things like require_relative 'config/environment'. Any news / insights on why rails behaves differently in this case?

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 :: constants in my callbacks in ApplicationController helped for me. Similar to https://github.com/activeadmin/activeadmin/issues/2490#issuecomment-25627837 . Very annoying issue to fix, eh!

Prefixing all the contants in our ApplicationController is what fixed this for us as well.

Interesting that this was reported shortly after d7a3ea90eed7f56fd5abdb4ae9f0764cc720e032

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 activeadmin-1.1.0 with rails-4.2.2 and ruby 2.2.1p85.
When I ran bin/rails g I got the error:

Circular dependency detected while autoloading constant AdminUser

I did that @jtomaszewski suggested and renamed admin_user.rb to admin_users.rb.
I also had to rename admin/news.rb to admin/newss.rb (Yes, that's 'ss'), before I could run the generator again.

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.

config.eager_load_paths accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the app directory of the application.

Hello, everyone. I have the same problem as i thought in issues

/.rvm/gems/ruby-2.3.1/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:508:in `load_missing_constant': Circular dependency detected while autoloading constant AdminUser (RuntimeError)

Rails v 5.1.4, Ruby v 2.3.1p112, ActiveAdmin 1.1.0
I see this problem when i tried to install active admin by command
"rails g active_admin:install"
and when try to start rails server

I tried to rename "app/admin/admin_user.rb" but nothing happen.
Listing issues few hours but cant understand what to do and how to fix it.

Prepending :: to referenced classes in my ApplicationController solved my issue!
https://stackoverflow.com/a/18423438/2701824

I found out the issue was that InheritedResources::Base were not reloaded. Although ActiveAdmin did all the reloading correctly(*), the base class it used wasn't refreshed and still pointed to out-dated ApplicationController.

It looks like we need to add mechanism to InheritedResources gem (also owned by ActiveAdmin) to do reloading correctly.

(byebug) Manage::PlatformSurveysController.superclass.superclass.superclass
InheritedResources::Base
(byebug) Manage::PlatformSurveysController.superclass.superclass.superclass.superclass == ApplicationController
false

ActiveAdmin reloaded the classes correctly in here
https://github.com/activeadmin/activeadmin/blob/e0ac14d0657fbba0ffd6623b46e6a755182f00da/lib/active_admin/application.rb#L190

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 ApplicationController is what fixed this for us as well.

rails 5.2.1
active admine -> 1.4.1
ruby 2.4.1p111

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gauthamns picture gauthamns  Â·  34Comments

seanlinsley picture seanlinsley  Â·  31Comments

stungeye picture stungeye  Â·  35Comments

robotmay picture robotmay  Â·  61Comments

ghost picture ghost  Â·  34Comments