Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4/ActiveSupport: Circular dependency detected while autoloading constant User

After running:

rails generate active_admin:resource Project

at the terminal I got the following error:

/Users/thalatta/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:460:in `load_missing_constant': Circular dependency detected while autoloading constant User (RuntimeError)
from /Users/thalatta/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:183:in `const_missing'
from /Users/thalatta/code/byrdtyme/app/admin/user.rb:1:in `<top (required)>'

Here is my Gemfile for reference:

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'



gem 'launchy'

gem 'devise',              github: 'plataformatec/devise'
gem 'responders',          github: 'plataformatec/responders'
gem 'inherited_resources', github: 'josevalim/inherited_resources'
gem 'ransack'
gem 'activeadmin',         github: 'gregbell/active_admin', branch: 'rails4'
gem 'formtastic',          github: 'justinfrench/formtastic'

gem 'spork'

gem 'rspec-rails'

gem 'capybara', '1.1.2'

gem 'cancan'

#TODO figure out how to resolve this! don't werk with Rails 4
#gem 'audited-activerecord'


# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

gem 'rspec-rails'


gem 'factory_girl_rails', '~> 4.0'
gem 'faker'

gem 'haml'
# Turbolinks makes following links in your web application faster. Read more:    https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

I tried following this post's advice: Circular dependency detected while autoloading constant User, but unfortunately activesupport, as far as I know, does not have a github where I can post an issue or see if it has been resolved.

Thanks for your time!

like image 355
Thalatta Avatar asked Aug 20 '13 21:08

Thalatta


1 Answers

Try removing the second mention of gem 'rspec-rails'

Also - check the first line of your Users Controller... it should read:

Class UsersController < ApplicationController

Someone has run in to this error before because they had 'UsersControllers' instead of UserController (see this post: Rails 4 Runtime error in controller: Circular dependency detected while autoloading constant).

Your new Gemfile will look like this:

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

gem 'launchy'

gem 'devise',              github: 'plataformatec/devise'
gem 'responders',          github: 'plataformatec/responders'
gem 'inherited_resources', github: 'josevalim/inherited_resources'
gem 'ransack'
gem 'activeadmin',         github: 'gregbell/active_admin', branch: 'rails4'
gem 'formtastic',          github: 'justinfrench/formtastic'

gem 'spork'

gem 'rspec-rails'

gem 'capybara', '1.1.2'

gem 'cancan'

#TODO figure out how to resolve this! don't werk with Rails 4
# gem 'audited-activerecord'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

gem 'factory_girl_rails', '~> 4.0'
gem 'faker'
gem 'haml'
# Turbolinks makes following links in your web application faster. Read more:        https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end
like image 91
Andrew Hendrie Avatar answered Oct 24 '22 03:10

Andrew Hendrie