Circular dependency detected while autoloading a constant

为君一笑 提交于 2019-12-10 10:06:19

问题


I upgraded Rails from version 3.1.2 (which worked fine) to 4.0, and got stuck with the following error:

circular dependency detected while autoloading constant Foo

I created a class ProductFactory, where I instantiate different models. For example:

p = Foo.new(params)

The model "Foo" is not always an ActiveRecord. Could anyone help me with this issue?


回答1:


This kind of issues often happen when you change the version of Rails. You maybe didnt update the gems on the right order.




回答2:


Best I'm aware, circular dependencies error messages usually occur when cascading includes go wrong by recursively requiring a file before it is fully loaded, e.g.:

# File A:
require 'B'
module Foo; end

# File B:
require 'A'
module Foo; end

Any odds this is the kind of situation you're ending up with?




回答3:


I had this error because I manually renamed controllers, routes etc etc and forgot to rename it in the first line of the files.

Was named

class AController < ApplicationController

instead of

class ARenamedController < ApplicationController

and I had gone and renamed all the other files individuall.

Not best practice I know, but I am learning and figuring it out, and in this case created the error this person is talking about. So if you got here through Google like I did, there is my solution.



来源:https://stackoverflow.com/questions/18921079/circular-dependency-detected-while-autoloading-a-constant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!