Я начал получать следующую ошибку при работе.
RuntimeError: Circular dependency detected while autoloading constant Ability
from active_support/dependencies.rb:492:in `load_missing_constant'
from active_support/dependencies.rb:184:in `const_missing'
from active_support/dependencies.rb:526:in `load_missing_constant'
from active_support/dependencies.rb:184:in `const_missing'
from active_support/dependencies.rb:526:in `load_missing_constant'
from active_support/dependencies.rb:184:in `const_missing'
from app/controllers/frontend/application_controller.rb:126:in `current_ability'
from cancan/controller_additions.rb:352:in `authorize!'
from app/controllers/documentable_count_controller.rb:5:in `index'
from action_controller/metal/implicit_render.rb:4:in `send_action'
from abstract_controller/base.rb:198:in `process_action'
from action_controller/metal/rendering.rb:10:in `process_action'
from abstract_controller/callbacks.rb:20:in `block in process_action'
from active_support/callbacks.rb:117:in `call'
from active_support/callbacks.rb:117:in `call'
from active_support/callbacks.rb:555:in `block (2 levels) in compile'
from active_support/callbacks.rb:505:in `call'
from active_support/callbacks.rb:505:in `call'
from active_support/callbacks.rb:92:in `__run_callbacks__'
from active_support/callbacks.rb:778:in `_run_process_action_callbacks'
from active_support/callbacks.rb:81:in `run_callbacks'
from abstract_controller/callbacks.rb:19:in `process_action'
from action_controller/metal/rescue.rb:29:in `process_action'
from action_controller/metal/instrumentation.rb:32:in `block in process_action'
from active_support/notifications.rb:164:in `block in instrument'
from active_support/notifications/instrumenter.rb:20:in `instrument'
from active_support/notifications.rb:164:in `instrument'
from action_controller/metal/instrumentation.rb:30:in `process_action'
from action_controller/metal/params_wrapper.rb:250:in `process_action'
from active_record/railties/controller_runtime.rb:18:in `process_action'
from abstract_controller/base.rb:137:in `process'
from action_view/rendering.rb:30:in `process'
from action_controller/metal.rb:196:in `dispatch'
from action_controller/metal/rack_delegation.rb:13:in `dispatch'
from action_controller/metal.rb:237:in `block in action'
from action_dispatch/routing/route_set.rb:74:in `call'
from action_dispatch/routing/route_set.rb:74:in `dispatch'
from action_dispatch/routing/route_set.rb:43:in `serve'
from action_dispatch/journey/router.rb:43:in `block in serve'
from action_dispatch/journey/router.rb:30:in `each'
from action_dispatch/journey/router.rb:30:in `serve'
from action_dispatch/routing/route_set.rb:817:in `call'
from rack/attack.rb:172:in `call'
from warden/manager.rb:36:in `block in call'
from warden/manager.rb:35:in `catch'
from warden/manager.rb:35:in `call'
from rack/etag.rb:24:in `call'
from rack/conditionalget.rb:25:in `call'
from rack/head.rb:13:in `call'
from action_dispatch/middleware/params_parser.rb:27:in `call'
from action_dispatch/middleware/flash.rb:260:in `call'
from rack/session/abstract/id.rb:225:in `context'
from rack/session/abstract/id.rb:220:in `call'
from action_dispatch/middleware/cookies.rb:560:in `call'
from active_record/query_cache.rb:36:in `call'
from active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
from action_dispatch/middleware/callbacks.rb:29:in `block in call'
from active_support/callbacks.rb:88:in `__run_callbacks__'
from active_support/callbacks.rb:778:in `_run_call_callbacks'
from active_support/callbacks.rb:81:in `run_callbacks'
from action_dispatch/middleware/callbacks.rb:27:in `call'
from action_dispatch/middleware/remote_ip.rb:78:in `call'
from action_dispatch/middleware/debug_exceptions.rb:17:in `call'
from action_dispatch/middleware/show_exceptions.rb:30:in `call'
from rails/rack/logger.rb:38:in `call_app'
from rails/rack/logger.rb:20:in `block in call'
from active_support/tagged_logging.rb:68:in `block in tagged'
from active_support/tagged_logging.rb:26:in `tagged'
from active_support/tagged_logging.rb:68:in `tagged'
from rails/rack/logger.rb:20:in `call'
from ahoy/engine.rb:22:in `call_with_quiet_ahoy'
from request_store/middleware.rb:19:in `call'
from action_dispatch/middleware/request_id.rb:21:in `call'
from rack/methodoverride.rb:22:in `call'
from rack/runtime.rb:18:in `call'
from active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
from action_dispatch/middleware/static.rb:120:in `call'
from rack/sendfile.rb:113:in `call'
from rack/cors.rb:97:in `call'
from raven/integrations/rack.rb:50:in `call'
from rails/engine.rb:518:in `call'
from rails/application.rb:165:in `call'
from rack/content_length.rb:15:in `call'
from puma/configuration.rb:225:in `call'
from puma/server.rb:658:in `handle_request'
from puma/server.rb:472:in `process_client'
from puma/server.rb:332:in `block in run'
from puma/thread_pool.rb:133:in `call'
from puma/thread_pool.rb:133:in `block in spawn_thread'
Я пытался проверить, есть ли у кого-то проблема, и в некоторых сообщениях говорилось, что для "config.eager_load" установлено значение true.Однако этот способ уже задан в рабочей среде.
Проблема начинается, когда код пытается проверить, авторизован ли пользователь для чтения здания в строке «authorize!: Read, @building».
class DocumentableCountController < ::Frontend::ApplicationController
before_action :redirect_if_no_building
def index
authorize! :read, @building
...
end
...
Вызывает следующий метод изнутри, где возникает ошибка, которая находится в строке "@current_ability || = Ability.new (заинтересованных лиц)".
module Frontend
class ApplicationController < ::ApplicationController
...
def current_ability
stakeholder = current_admin || current_user
@current_ability ||= Ability.new(stakeholder)
end
end
end
Выдает ошибку:
RuntimeError: Circular dependency detected while autoloading constant Ability
Ожидается, что этой ошибки не будет.
Дополнительная информация
Следующий код является классом ":: ApplicationController", унаследованным интерфейсом модуля выше..
class ApplicationController < ActionController::Base
include HasFrontendPartner
include RescuesNotFound
protect_from_forgery with: :exception
rescue_from CanCan::AccessDenied do |exception|
respond_to do |format|
format.html { redirect_to "/403", notice: exception.message }
format.json { render json: { error: exception.message }, status: 403 }
end
end
end