Pol0nium
Pol0nium

Reputation: 1386

Circular dependency detected while autoloading a constant

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?

Upvotes: 3

Views: 7433

Answers (3)

Jay Killeen
Jay Killeen

Reputation: 2922

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.

Upvotes: 3

Nicolas HENAUX
Nicolas HENAUX

Reputation: 1686

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

Upvotes: 2

Denis de Bernardy
Denis de Bernardy

Reputation: 78591

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?

Upvotes: 3

Related Questions