Обнаружена циклическая зависимость при автозагрузке константного контроллера
Привет! Я потерял целый день на этом. Это дерево моего проекта:app
|__controllers
|__application_controller.rb
|__feedbacks_controller.rb
|__feedbacks
|__given_feedbacks_controller.rb
|__received_feedbacks_controller.rb
feedbacks_controller.rb
class FeedbacksController < ApplicationController
...
end
given_feedbacks_controller.rb
class Feedbacks::GivenFeedbacksController < FeedbacksController
...
end
received_feedbacks_controller.rb
class Feedbacks::ReceivedFeedbacksController < FeedbacksController
...
end
конфиг /routes.rb
...
resources :users, except: [:new, :edit] do
resources :given_feedbacks,
only: [:index],
controller: 'feedbacks/given_feedbacks'
resources :received_feedbacks,
only: [:index],
controller: 'feedbacks/received_feedbacks'
end
resources :feedbacks, only: [:show, :create, :update, :destroy]
...
Я понял, что проблема, вероятно, в наследстве, потому что если я это сделаю:
given_feedbacks_controller.rb
class Feedbacks::GivenFeedbacksController < AppicationController
...
end
received_feedbacks_controller.rb
class Feedbacks::ReceivedFeedbacksController < AppicationController
...
end
ошибка не возникает.
Я попробовал в моем test.rb
обе эти конфигурации:
config.eager_load = true
а также
config.allow_concurrency = false
и в любом случае ошибка происходит и в разработке.
Здесь ошибка, возникающая при выполнении теста:
/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:492:in 'load_missing_constant': Circular dependency detected while autoloading constant Feedbacks::GivenFeedbacksController (RuntimeError)
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:184:in 'const_missing'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:263:in 'const_get'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:263:in 'block in constantize'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:259:in 'each'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:259:in 'inject'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:259:in 'constantize'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:566:in 'get'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:597:in 'constantize'
from /.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:72:in 'controller_reference'
from /.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:62:in 'controller'
from /.rvm/gems/ruby-2.2.1/gems/apipie-rails-0.3.5/lib/apipie/application.rb:59:in 'route_app_controller'
from /.rvm/gems/ruby-2.2.1/gems/apipie-rails-0.3.5/lib/apipie/application.rb:69:in 'block in routes_for_action'
from /.rvm/gems/ruby-2.2.1/gems/apipie-rails-0.3.5/lib/apipie/application.rb:68:in 'select'
from /.rvm/gems/ruby-2.2.1/gems/apipie-rails-0.3.5/lib/apipie/application.rb:68:in 'routes_for_action'
from /.rvm/gems/ruby-2.2.1/gems/apipie-rails-0.3.5/lib/apipie/apipie_module.rb:18:in 'method_missing'
from /.rvm/gems/ruby-2.2.1/gems/apipie-rails-0.3.5/lib/apipie/method_description.rb:171:in 'api_data'
from /.rvm/gems/ruby-2.2.1/gems/apipie-rails-0.3.5/lib/apipie/method_description.rb:26:in 'initialize'
from /.rvm/gems/ruby-2.2.1/gems/apipie-rails-0.3.5/lib/apipie/application.rb:92:in 'new'
from /.rvm/gems/ruby-2.2.1/gems/apipie-rails-0.3.5/lib/apipie/application.rb:92:in 'block in define_method_description'
from /.rvm/gems/ruby-2.2.1/gems/apipie-rails-0.3.5/lib/apipie/application.rb:84:in 'each'
from /.rvm/gems/ruby-2.2.1/gems/apipie-rails-0.3.5/lib/apipie/application.rb:84:in 'define_method_description'
from /.rvm/gems/ruby-2.2.1/gems/apipie-rails-0.3.5/lib/apipie/apipie_module.rb:18:in 'method_missing'
from /.rvm/gems/ruby-2.2.1/gems/apipie-rails-0.3.5/lib/apipie/dsl_definition.rb:408:in 'method_added'
from /development/on_call_work/app/controllers/feedbacks_controller.rb:34:in '<class:FeedbacksController>'
from /development/on_call_work/app/controllers/feedbacks_controller.rb:1:in '<top (required)>'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:457:in 'load'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:457:in 'block in load_file'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:647:in 'new_constants_in'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:456:in 'load_file'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:354:in 'require_or_load'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:494:in 'load_missing_constant'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:184:in 'const_missing'
from /development/on_call_work/app/controllers/feedbacks/given_feedbacks_controller.rb:2:in '<top (required)>'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:457:in 'load'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:457:in 'block in load_file'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:647:in 'new_constants_in'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:456:in 'load_file'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:354:in 'require_or_load'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:317:in 'depend_on'
from /.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:233:in 'require_dependency'
from /.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/engine.rb:472:in 'block (2 levels) in eager_load!'
from /.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/engine.rb:471:in 'each'
from /.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/engine.rb:471:in 'block in eager_load!'
from /.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/engine.rb:469:in 'each'
from /.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/engine.rb:469:in 'eager_load!'
from /.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/engine.rb:346:in 'eager_load!'
from /.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/application/finisher.rb:56:in 'each'
from /.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/application/finisher.rb:56:in 'block in <module:Finisher>'
from /.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/initializable.rb:30:in 'instance_exec'
from /.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/initializable.rb:30:in 'run'
from /.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/initializable.rb:55:in 'block in run_initializers'
from /.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:226:in 'block in tsort_each'
from /.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:348:in 'block (2 levels) in each_strongly_connected_component'
from /.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:429:in 'each_strongly_connected_component_from'
from /.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:347:in 'block in each_strongly_connected_component'
from /.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in 'each'
from /.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in 'call'
from /.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in 'each_strongly_connected_component'
from /.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:224:in 'tsort_each'
from /.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:203:in 'tsort_each'
from /.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/initializable.rb:54:in 'run_initializers'
from /.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/application.rb:352:in 'initialize!'
from /development/on_call_work/config/environment.rb:5:in '<top (required)>'
from /development/on_call_work/spec/rails_helper.rb:3:in 'require'
from /development/on_call_work/spec/rails_helper.rb:3:in '<top (required)>'
from /development/on_call_work/spec/controllers/feedbacks/given_feedbacks_controller_spec.rb:1:in 'require'
from /development/on_call_work/spec/controllers/feedbacks/given_feedbacks_controller_spec.rb:1:in '<top (required)>'
from /.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1361:in 'load'
from /.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1361:in 'block in load_spec_files'
from /.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1359:in 'each'
from /.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1359:in 'load_spec_files'
from /.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:102:in 'setup'
from /.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:88:in 'run'
from /.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:73:in 'run'
from /.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:41:in 'invoke'
from /.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/exe/rspec:4:in '<top (required)>'
from /.rvm/gems/ruby-2.2.1/bin/rspec:23:in 'load'
from /.rvm/gems/ruby-2.2.1/bin/rspec:23:in '<main>'
from /.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in 'eval'
from /.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in '<main>'
конечно, ошибка возникает как из Given_feedbacks_controller, так и Receive_feedbacks_controller