form all active ruby-on-rails activeadmin ruby-on-rails-4

ruby on rails - all - ArgumentError: se ha eliminado una copia de ApplicationController del árbol del módulo, pero todavía está activa



form active admin (5)

Estoy usando ActiveAdmin (con gemset personalizado para Rails 4) con Rails 4.0.0.rc2. La aplicación también tiene un código de autorización creado a medida basado en los envíos de raíles #385 y #386 .

Cuando cambio algo en un archivo de recursos de ActiveAdmin y trato de actualizar la página del navegador, obtengo este error en el método current_permission :

ArgumentError at / admin / courses

Se ha eliminado una copia de ApplicationController del árbol de módulos pero aún está activa.

Si intento actualizar nuevamente, obtengo:

Dependencia circular detectada mientras se carga automáticamente la constante Permisos

Creo que este problema tiene algo que ver con la carga automática de las clases en el modo de desarrollo, después de un cambio en el archivo de origen. He visto publicaciones problemáticas similares, pero son para rails 2.3.x. Además, la solución parece estar especificando que no se puede unloadable en el controlador que arroja este error, pero no estoy seguro de dónde colocar este fragmento en ActiveAdmin.

Esto podría no tener nada que ver con ActiveAdmin tampoco. Puede tratarse de cómo se ha construido la clase de permisos y su uso dentro del controlador de aplicaciones. Si agrego un skip_before_filter :authorize en la clase de recurso ActiveAdmin, este error desaparece.

ApplicationController:

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_filter :authenticate_user! before_filter :authorize delegate :allow_action?, to: :current_permission helper_method :allow_action? delegate :allow_param?, to: :current_permission helper_method :allow_param? private def current_permission @current_permission ||= Permissions.permission_for(current_user) end def current_resource nil end def authorize if current_permission.allow_action?(params[:controller], params[:action], current_resource) current_permission.permit_params! params else redirect_to root_url, alert: "Not authorized." end end end

Permisos.rb:

module Permissions def self.permission_for(user) if user.nil? GuestPermission.new elsif user.admin? AdminPermission.new(user) else UserPermission.new(user) end end end

admin / courses.rb:

ActiveAdmin.register Course do index do column :name column :description column :duration column :status column :price default_actions end filter :discipline filter :level filter :lessons filter :name filter :status end

Gemfile (líneas relevantes):

gem ''rails'', ''4.0.0.rc2'' # Use puma as the app server gem ''puma'' # Administration - Temporary github refs until rails 4 compatible releases gem ''responders'', github: ''plataformatec/responders'' gem ''inherited_resources'', github: ''josevalim/inherited_resources'' gem ''ransack'', github: ''ernie/ransack'', branch: ''rails-4'' gem ''activeadmin'', github: ''gregbell/active_admin'', branch: ''rails4'' gem ''formtastic'', github: ''justinfrench/formtastic''

ArgumentError:

ArgumentError - A copy of ApplicationController has been removed from the module tree but is still active!: activesupport (4.0.0.rc2) lib/active_support/dependencies.rb:445:in `load_missing_constant'' activesupport (4.0.0.rc2) lib/active_support/dependencies.rb:183:in `const_missing'' rspec-core (2.13.1) lib/rspec/core/backward_compatibility.rb:24:in `const_missing'' app/controllers/application_controller.rb:17:in `current_permission'' app/controllers/application_controller.rb:25:in `authorize'' activesupport (4.0.0.rc2) lib/active_support/callbacks.rb:417:in `_run__1040990970961152968__process_action__callbacks'' activesupport (4.0.0.rc2) lib/active_support/callbacks.rb:80:in `run_callbacks'' actionpack (4.0.0.rc2) lib/abstract_controller/callbacks.rb:17:in `process_action'' actionpack (4.0.0.rc2) lib/action_controller/metal/rescue.rb:29:in `process_action'' actionpack (4.0.0.rc2) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'' activesupport (4.0.0.rc2) lib/active_support/notifications.rb:159:in `block in instrument'' activesupport (4.0.0.rc2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'' activesupport (4.0.0.rc2) lib/active_support/notifications.rb:159:in `instrument'' actionpack (4.0.0.rc2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'' actionpack (4.0.0.rc2) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'' activerecord (4.0.0.rc2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'' actionpack (4.0.0.rc2) lib/abstract_controller/base.rb:136:in `process'' actionpack (4.0.0.rc2) lib/abstract_controller/rendering.rb:44:in `process'' actionpack (4.0.0.rc2) lib/action_controller/metal.rb:195:in `dispatch'' actionpack (4.0.0.rc2) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'' actionpack (4.0.0.rc2) lib/action_controller/metal.rb:231:in `block in action'' actionpack (4.0.0.rc2) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'' actionpack (4.0.0.rc2) lib/action_dispatch/routing/route_set.rb:48:in `call'' actionpack (4.0.0.rc2) lib/action_dispatch/journey/router.rb:71:in `block in call'' actionpack (4.0.0.rc2) lib/action_dispatch/journey/router.rb:59:in `call'' actionpack (4.0.0.rc2) lib/action_dispatch/routing/route_set.rb:655:in `call'' omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'' omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'' omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'' omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'' omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'' omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'' newrelic_rpm (3.6.4.122) lib/new_relic/rack/error_collector.rb:12:in `call'' newrelic_rpm (3.6.4.122) lib/new_relic/rack/agent_hooks.rb:22:in `call'' newrelic_rpm (3.6.4.122) lib/new_relic/rack/browser_monitoring.rb:16:in `call'' newrelic_rpm (3.6.4.122) lib/new_relic/rack/developer_mode.rb:28:in `call'' meta_request (0.2.7) lib/meta_request/middlewares/app_request_handler.rb:13:in `call'' rack-contrib (1.1.0) lib/rack/contrib/response_headers.rb:17:in `call'' meta_request (0.2.7) lib/meta_request/middlewares/headers.rb:16:in `call'' meta_request (0.2.7) lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'' warden (1.2.1) lib/warden/manager.rb:35:in `block in call'' warden (1.2.1) 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.rc2) lib/action_dispatch/middleware/params_parser.rb:27:in `call'' actionpack (4.0.0.rc2) 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.rc2) lib/action_dispatch/middleware/cookies.rb:486:in `call'' activerecord (4.0.0.rc2) lib/active_record/query_cache.rb:36:in `call'' activerecord (4.0.0.rc2) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'' activerecord (4.0.0.rc2) lib/active_record/migration.rb:369:in `call'' actionpack (4.0.0.rc2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'' activesupport (4.0.0.rc2) lib/active_support/callbacks.rb:373:in `_run__2183739952227501342__call__callbacks'' activesupport (4.0.0.rc2) lib/active_support/callbacks.rb:80:in `run_callbacks'' actionpack (4.0.0.rc2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'' actionpack (4.0.0.rc2) lib/action_dispatch/middleware/reloader.rb:64:in `call'' actionpack (4.0.0.rc2) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'' better_errors (0.9.0) lib/better_errors/middleware.rb:84:in `protected_app_call'' better_errors (0.9.0) lib/better_errors/middleware.rb:79:in `better_errors_call'' better_errors (0.9.0) lib/better_errors/middleware.rb:56:in `call'' actionpack (4.0.0.rc2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'' actionpack (4.0.0.rc2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'' railties (4.0.0.rc2) lib/rails/rack/logger.rb:38:in `call_app'' railties (4.0.0.rc2) lib/rails/rack/logger.rb:21:in `block in call'' activesupport (4.0.0.rc2) lib/active_support/tagged_logging.rb:67:in `block in tagged'' activesupport (4.0.0.rc2) lib/active_support/tagged_logging.rb:25:in `tagged'' activesupport (4.0.0.rc2) lib/active_support/tagged_logging.rb:67:in `tagged'' railties (4.0.0.rc2) lib/rails/rack/logger.rb:21:in `call'' actionpack (4.0.0.rc2) 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.rc2) 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.rc2) lib/action_dispatch/middleware/static.rb:64:in `call'' railties (4.0.0.rc2) lib/rails/engine.rb:511:in `call'' railties (4.0.0.rc2) lib/rails/application.rb:97:in `call'' rack (1.5.2) lib/rack/content_length.rb:14:in `call'' puma (2.1.1) lib/puma/server.rb:369:in `handle_request'' puma (2.1.1) lib/puma/server.rb:246:in `process_client'' puma (2.1.1) lib/puma/server.rb:145:in `block in run'' puma (2.1.1) lib/puma/thread_pool.rb:92:in `block in spawn_thread''

RuntimeError: Dependencia circular:

RuntimeError - Circular dependency detected while autoloading constant Permissions: activesupport (4.0.0.rc2) lib/active_support/dependencies.rb:460:in `load_missing_constant'' activesupport (4.0.0.rc2) lib/active_support/dependencies.rb:183:in `const_missing'' rspec-core (2.13.1) lib/rspec/core/backward_compatibility.rb:24:in `const_missing'' activesupport (4.0.0.rc2) lib/active_support/dependencies.rb:686:in `remove_constant'' activesupport (4.0.0.rc2) lib/active_support/dependencies.rb:516:in `block in remove_unloadable_constants!'' activesupport (4.0.0.rc2) lib/active_support/dependencies.rb:516:in `remove_unloadable_constants!'' activesupport (4.0.0.rc2) lib/active_support/dependencies.rb:300:in `clear'' railties (4.0.0.rc2) lib/rails/application/finisher.rb:90:in `block (2 levels) in <module:Finisher>'' activesupport (4.0.0.rc2) lib/active_support/file_update_checker.rb:75:in `execute'' railties (4.0.0.rc2) lib/rails/application/finisher.rb:105:in `block (2 levels) in <module:Finisher>'' activesupport (4.0.0.rc2) lib/active_support/callbacks.rb:377:in `_run__2753119820186226816__prepare__callbacks'' activesupport (4.0.0.rc2) lib/active_support/callbacks.rb:80:in `run_callbacks'' actionpack (4.0.0.rc2) lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'' actionpack (4.0.0.rc2) lib/action_dispatch/middleware/reloader.rb:62:in `call'' actionpack (4.0.0.rc2) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'' better_errors (0.9.0) lib/better_errors/middleware.rb:84:in `protected_app_call'' better_errors (0.9.0) lib/better_errors/middleware.rb:79:in `better_errors_call'' better_errors (0.9.0) lib/better_errors/middleware.rb:56:in `call'' actionpack (4.0.0.rc2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'' actionpack (4.0.0.rc2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'' railties (4.0.0.rc2) lib/rails/rack/logger.rb:38:in `call_app'' railties (4.0.0.rc2) lib/rails/rack/logger.rb:21:in `block in call'' activesupport (4.0.0.rc2) lib/active_support/tagged_logging.rb:67:in `block in tagged'' activesupport (4.0.0.rc2) lib/active_support/tagged_logging.rb:25:in `tagged'' activesupport (4.0.0.rc2) lib/active_support/tagged_logging.rb:67:in `tagged'' railties (4.0.0.rc2) lib/rails/rack/logger.rb:21:in `call'' actionpack (4.0.0.rc2) 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.rc2) 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.rc2) lib/action_dispatch/middleware/static.rb:64:in `call'' railties (4.0.0.rc2) lib/rails/engine.rb:511:in `call'' railties (4.0.0.rc2) lib/rails/application.rb:97:in `call'' rack (1.5.2) lib/rack/content_length.rb:14:in `call'' puma (2.1.1) lib/puma/server.rb:369:in `handle_request'' puma (2.1.1) lib/puma/server.rb:246:in `process_client'' puma (2.1.1) lib/puma/server.rb:145:in `block in run'' puma (2.1.1) lib/puma/thread_pool.rb:92:in `block in spawn_thread''

Cualquier pista ayudará. Avíseme si necesita ver otros fragmentos de código en la aplicación.


En ti development.rb intentas poner temporalmente

config.cache_classes = true

Funcionó para mí


No estoy seguro exactamente de por qué está sucediendo esto, pero encontré un campo de trabajo. Cambia esto:

def current_permission @current_permission ||= Permissions.permission_for(current_user) end

A esto:

def current_permission @current_permission ||= ::Permissions.permission_for(current_user) end

El error se plantea en este punto en 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

El problema solo ocurre cuando no califica por completo el nombre de la constante, por lo que Rails intenta buscarlo en el espacio de nombres ApplicationController .


No estoy usando ActiveAdmin, pero acabo de experimentar una dependencia circular con ApplicationController.

El problema era que un módulo auxiliar se declaró incorrectamente:

app/helpers/home_helper.rb

fue declarado con:

module StaticHelper

Después de arreglar esto, todo fue color de rosa. No investigué por qué sucedió esto y Rails no devolvió un mensaje de error más inteligente.


Para futuros visitantes, pensé en proporcionar algunas aclaraciones sobre el problema original a pesar de que la pregunta es bastante antigua y ya hay una respuesta aceptada.

ArgumentError: A copy of X has been removed from the module tree but is still active cuando intenta acceder a una clase recargada automáticamente (en el directorio de la aplicación) desde una que no se recarga automáticamente (en el directorio lib).


Puedes intentar poner esta línea en tu config/initializers/active_admin.rb :

config.skip_before_filter :load_footer_variables

Como sugerido here .