RuntimeError:自动加载常量时检测到循环依赖关系(Rails_Admin)

时间:2014-10-02 17:00:57

标签: ruby-on-rails ruby rails-admin

我使用Rails_Admin 0.6.3与Ruby 2.1.1和Rails 4.1.6。我在模型类别和主题之间建立了多对多关系,以及数量和主题。 Rails_Admin在开发中运行良好,但是当我尝试在生产中加载它时,我收到此错误:RuntimeError (Circular dependency detected while autoloading constant Categorytopic)

我有以下模型(以及其他模型):

class Category < ActiveRecord::Base
    has_many :category_topics
    has_many :topics, through: :category_topics
    validates :name, uniqueness: true
end

class CategoryTopic < ActiveRecord::Base
    belongs_to :category
    belongs_to :topic
end

class Topic < ActiveRecord::Base
    has_many :category_topics
    has_many :categories, through: :category_topics
    has_many :quantity_topics
    has_many :quantities, through: :quantity_topics
    validates :name, uniqueness: true
end

这是完整的痕迹:

2014-10-02T16:38:58.904301+00:00 app[web.1]: RuntimeError (Circular dependency detected while autoloading constant Categorytopic):
2014-10-02T16:38:58.904313+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rails_admin-0.6.3/lib/rails_admin/abstract_model.rb:18:in `new'
2014-10-02T16:38:58.904335+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:149:in `call'
2014-10-02T16:38:58.904345+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:166:in `call'
2014-10-02T16:38:58.904362+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:166:in `call'
2014-10-02T16:38:58.904393+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
2014-10-02T16:38:58.904399+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_controller/metal.rb:196:in `dispatch'
2014-10-02T16:38:58.904407+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/journey/router.rb:59:in `each'
2014-10-02T16:38:58.904415+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/journey/router.rb:59:in `each'
2014-10-02T16:38:58.904437+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
2014-10-02T16:38:58.904446+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
2014-10-02T16:38:58.904459+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/request_id.rb:21:in `call'
2014-10-02T16:38:58.904427+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
2014-10-02T16:38:58.904447+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
2014-10-02T16:38:58.904457+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.6/lib/rails/rack/logger.rb:20:in `call'
2014-10-02T16:38:58.904484+00:00 app[web.1]:   vendor/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
2014-10-02T16:38:58.904436+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
2014-10-02T16:38:58.904452+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/tagged_logging.rb:68:in `block in tagged'
2014-10-02T16:38:58.904465+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
2014-10-02T16:38:58.904477+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
2014-10-02T16:38:58.904426+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
2014-10-02T16:38:58.904456+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/tagged_logging.rb:68:in `tagged'
2014-10-02T16:38:58.904479+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
2014-10-02T16:38:58.904438+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/cookies.rb:560:in `call'
2014-10-02T16:38:58.904462+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
2014-10-02T16:38:58.904466+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.6/lib/rails/engine.rb:514:in `call'
2014-10-02T16:38:58.904480+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
2014-10-02T16:38:58.904441+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
2014-10-02T16:38:58.904451+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.6/lib/rails/rack/logger.rb:20:in `block in call'
2014-10-02T16:38:58.904460+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
2014-10-02T16:38:58.904434+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/flash.rb:254:in `call'
2014-10-02T16:38:58.904449+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
2014-10-02T16:38:58.904467+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.6/lib/rails/application.rb:144:in `call'
2014-10-02T16:38:58.904482+00:00 app[web.1]:   vendor/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
2014-10-02T16:38:58.904443+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
2014-10-02T16:38:58.904445+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
2014-10-02T16:38:58.904455+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/tagged_logging.rb:26:in `tagged'
2014-10-02T16:38:58.904486+00:00 app[web.1]: 
2014-10-02T16:38:58.904444+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:82:in `run_callbacks'
2014-10-02T16:38:58.904450+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.6/lib/rails/rack/logger.rb:38:in `call_app'
2014-10-02T16:38:58.904461+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
2014-10-02T16:38:58.904485+00:00 app[web.1]: 
2014-10-02T16:38:58.904433+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
2014-10-02T16:38:58.904440+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.6/lib/active_record/query_cache.rb:36:in `call'
2014-10-02T16:38:58.904463+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/static.rb:64:in `call'
2014-10-02T16:38:58.904481+00:00 app[web.1]:   vendor/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
2014-10-02T16:38:58.904313+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rails_admin-0.6.3/lib/rails_admin/abstract_model.rb:18:in `new'
2014-10-02T16:38:58.904335+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:149:in `call'
2014-10-02T16:38:58.904345+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:166:in `call'
2014-10-02T16:38:58.904362+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:166:in `call'
2014-10-02T16:38:58.904393+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
2014-10-02T16:38:58.904399+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_controller/metal.rb:196:in `dispatch'
2014-10-02T16:38:58.904407+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/journey/router.rb:59:in `each'
2014-10-02T16:38:58.904415+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/journey/router.rb:59:in `each'
2014-10-02T16:38:58.904437+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
2014-10-02T16:38:58.904446+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
2014-10-02T16:38:58.904459+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/request_id.rb:21:in `call'
2014-10-02T16:38:58.904427+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
2014-10-02T16:38:58.904447+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
2014-10-02T16:38:58.904457+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.6/lib/rails/rack/logger.rb:20:in `call'
2014-10-02T16:38:58.904484+00:00 app[web.1]:   vendor/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
2014-10-02T16:38:58.904436+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
2014-10-02T16:38:58.904452+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/tagged_logging.rb:68:in `block in tagged'
2014-10-02T16:38:58.904465+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
2014-10-02T16:38:58.904477+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
2014-10-02T16:38:58.904426+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
2014-10-02T16:38:58.904456+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/tagged_logging.rb:68:in `tagged'
2014-10-02T16:38:58.904479+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
2014-10-02T16:38:58.904438+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/cookies.rb:560:in `call'
2014-10-02T16:38:58.904462+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
2014-10-02T16:38:58.904466+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.6/lib/rails/engine.rb:514:in `call'
2014-10-02T16:38:58.904480+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
2014-10-02T16:38:58.904441+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
2014-10-02T16:38:58.904451+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.6/lib/rails/rack/logger.rb:20:in `block in call'
2014-10-02T16:38:58.904460+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
2014-10-02T16:38:58.904434+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/flash.rb:254:in `call'
2014-10-02T16:38:58.904449+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
2014-10-02T16:38:58.904467+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.6/lib/rails/application.rb:144:in `call'
2014-10-02T16:38:58.904482+00:00 app[web.1]:   vendor/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
2014-10-02T16:38:58.904443+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
2014-10-02T16:38:58.904445+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
2014-10-02T16:38:58.904455+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/tagged_logging.rb:26:in `tagged'
2014-10-02T16:38:58.904486+00:00 app[web.1]: 
2014-10-02T16:38:58.904444+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/callbacks.rb:82:in `run_callbacks'
2014-10-02T16:38:58.904450+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.6/lib/rails/rack/logger.rb:38:in `call_app'
2014-10-02T16:38:58.904461+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
2014-10-02T16:38:58.904485+00:00 app[web.1]: 
2014-10-02T16:38:58.904433+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
2014-10-02T16:38:58.904440+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.6/lib/active_record/query_cache.rb:36:in `call'
2014-10-02T16:38:58.904463+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/middleware/static.rb:64:in `call'
2014-10-02T16:38:58.904481+00:00 app[web.1]:   vendor/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'

不完全确定这里有什么问题。令人费解的是,为什么这会在开发中起作用而不是在Heroku中。

1 个答案:

答案 0 :(得分:0)

原来这是一个菜鸟的错误。我拼错了模型文件名。