我是Ruby on Rails的新手。运行'bundle'命令进行更新/安装后,当我尝试rails s
或rails g mongoid:config
控制台返回此消息时,该消息以:
/home/myUser/proyect/config/environments/development.rb:50:in `block in <top (required)>': uninitialized constant ActiveSupport::EventedFileUpdateChecker (NameError)
这是我的Gemfile(是的,我想使用MongoDB作为数据库):
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Mongoid as the database
gem 'mongoid', '~> 5.1.0'
# Use bson
gem 'bson_ext'
# Use Puma as the app server
gem 'puma', '~> 3.0'
#Use Haml for html
gem 'haml'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5.x'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console'
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
config / environments / development.rb 文件:
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800'
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end
答案 0 :(得分:5)
根据Rails changelogs,config.file_watcher
中引入了Rails 5
选项。它允许您根据文件更改进行自动重新加载。此功能取决于listener
gem,并且您已在gemfile中列出它。但对我来说可疑的是你的Rails
版本!
gem 'rails', '4.2.6'
# but rails 4 does not support that feature!
看起来您已经从另一个版本的development.rb
框架,另一个项目中复制了Gemfile(或Rails
配置?),或者手动将您的gemfile版本更改为不适当的状态。
我可以建议你的两个选择:
要将rails gemfile版本更改为最新版本,如下所示:
gem 'rails', github: 'rails/rails'
再次bundle
;
从配置文件中删除config.file_watcher
行。
答案 1 :(得分:2)
通常会发生这种情况,因为您安装的Rails版本比.railsrc
或template.rb
中要求的版本更新。
如果是这种情况,当您运行rails new my_new_app
时,默认情况下会使用最新版本来处理该过程的早期步骤,但是一旦安装了模板/ railsrc版本,后面的步骤就会使用此版本。这会导致兼容性问题。
您可以通过将rails -v
(在您调用rails new
的目录中)的输出与.railsrc
或{{{{}}中的内容进行比较来验证这是您的问题。 1}}。如果它们不同,可以轻松解决:
重新创建您的Rails应用,在命令行调用中从template.rb
或.railsrc
指定相同的Rails版本:
template.rb
答案 2 :(得分:1)
如果您删除config.file_watcher = ActiveSupport::EventedFileUpdateChecker
,它将有效。它检测源代码中的变化以异步刷新,但它也取决于listen
gem,因为您是初学者,它只会给您带来麻烦。应该没有它。