任何 rails 命令对我都不起作用。我通过 rvm 安装了几个版本的 ruby。我尝试安装所有版本的 rails,它们确实安装成功,但是对于所有版本,每当我在项目目录中运行 any rails 命令时,我都会遇到以下错误:
~ rails new blog
Traceback (most recent call last):
1: from bin/rails:3:in `<main>'
bin/rails:3:in `require_relative': cannot load such file -- /Users/Am33d/Documents/config/boot (LoadError)
我尝试查找错误,但没有找到任何解决方案。
如何解决这个问题?我正在使用 macOS Mojave (10.14.6)
最佳答案
此错误表明由于某种原因您的配置目录中没有 boot.rb
文件。运行 rails 命令时——无论您是将它们作为 bin/rails [command]
还是 bundle exec rails [command]
运行,运行 bin/rails
文件。该文件通常有一行 require_relative '../config/boot
。新 Rails 6 应用程序中的样板 bin/rails
文件是:
#!/usr/bin/env ruby
begin
load File.expand_path('../spring', __FILE__)
rescue LoadError => e
raise unless e.message.include?('spring')
end
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
要简单地解决此问题,您可以通过从应用程序的根目录运行 touch config/boot.rb
来创建一个空白文件,这本身会抑制错误。话虽如此,您最好还是创建一个包含有用信息的 config/boot.rb
文件。样板 config/boot.rb
文件是这样的
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' # Set up gems listed in the Gemfile.
require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
如果没有这个文件,您就不一定能正确地从您的 gemfile 中加载 gem 或使用 bootsnap 缓存操作。
关于ruby-on-rails - 当我们运行任何 rails 命令 : "` require_relative': cannot load such file "时,如何解决以下错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61711550/