Rails 4/ActiveSupport:自动加载常量用户时检测到循环依赖性

Tha*_*tta 6 ruby-on-rails-4

运行后:

rails generate active_admin:resource Project
Run Code Online (Sandbox Code Playgroud)

在终端我得到以下错误:

/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)>'
Run Code Online (Sandbox Code Playgroud)

这是我的Gemfile供参考:

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
Run Code Online (Sandbox Code Playgroud)

我尝试按照这篇文章的建议:在自动加载常量用户时检测到循环依赖,但遗憾的是,据我所知,activesupport没有github我可以发布问题或查看是否已解决.

谢谢你的时间!

And*_*rie 2

尝试删除第二次提到的 gem 'rspec-rails'

另外 - 检查用户控制器的第一行...它应该是:

类 UsersController < 应用程序控制器

之前有人遇到过此错误,因为他们使用的是“UsersControllers”而不是 UserController(请参阅这篇文章:控制器中的 Rails 4 运行时错误:自动加载常量时检测到循环依赖)。

您的新 Gemfile 将如下所示:

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
Run Code Online (Sandbox Code Playgroud)