Rails 4 / ActiveSupport: detected cyclic dependency on autoload of a constant User

After launch:

rails generate active_admin:resource Project 

on the terminal, I received 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 this post : A circular dependency was detected during regular user startup , but, unfortunately, support is active, as far as I know, does not have github where I can post a question or see if it was resolved.

Thank you for your time!

+6
source share
1 answer

Try to remove the second mention of gem 'rspec-rails'

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

Class UsersController <ApplicationController

Someone had run this error earlier because they had "UserControllers" instead of the UserController (see this post: Rails 4 Runtime error in the controller: a cyclic dependency was detected when the constant was loaded ).

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 
+2
source

Source: https://habr.com/ru/post/952160/


All Articles