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?
This kind of issues often happen when you change the version of Rails. You maybe didnt update the gems on the right order.
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?
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