所以我犯了一个巨大的错误,删除了一个计划从git克隆它的rails应用程序。现在我陷入困境,没有让我的服务器使用rails运行。
我一直收到以下错误,我不知道如何解决它。
Users/macuser/Desktop/Freelance1/config/application.rb:18:in `initialize': No such file or directory @ rb_sysopen - /Users/macuser/Desktop/Freelance1/config/local_env.yml (Errno::ENOENT)
from /Users/macuser/Desktop/Freelance1/config/application.rb:18:in `open'
from /Users/macuser/Desktop/Freelance1/config/application.rb:18:in `block in <class:Application>'
from /usr/local/lib/ruby/gems/2.4.0/gems/activesupport-5.1.3/lib/active_support/lazy_load_hooks.rb:43:in `execute_hook'
from /usr/local/lib/ruby/gems/2.4.0/gems/activesupport-5.1.3/lib/active_support/lazy_load_hooks.rb:35:in `block in on_load'
from /usr/local/lib/ruby/gems/2.4.0/gems/activesupport-5.1.3/lib/active_support/lazy_load_hooks.rb:34:in `each'
from /usr/local/lib/ruby/gems/2.4.0/gems/activesupport-5.1.3/lib/active_support/lazy_load_hooks.rb:34:in `on_load'
from /usr/local/lib/ruby/gems/2.4.0/gems/railties-5.1.3/lib/rails/railtie/configuration.rb:53:in `before_configuration'
from /Users/macuser/Desktop/Freelance1/config/application.rb:16:in `<class:Application>'
from /Users/macuser/Desktop/Freelance1/config/application.rb:10:in `<module:SSS>'
from /Users/macuser/Desktop/Freelance1/config/application.rb:9:in `<top (required)>'
from /usr/local/lib/ruby/gems/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:129:in `require'
from /usr/local/lib/ruby/gems/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:129:in `block in perform'
from /usr/local/lib/ruby/gems/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:126:in `tap'
from /usr/local/lib/ruby/gems/2.4.0/gems/railties-5.1.3/lib/rails/commands/server/server_command.rb:126:in `perform'
from /usr/local/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from /usr/local/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from /usr/local/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
from /usr/local/lib/ruby/gems/2.4.0/gems/railties-5.1.3/lib/rails/command/base.rb:63:in `perform'
from /usr/local/lib/ruby/gems/2.4.0/gems/railties-5.1.3/lib/rails/command.rb:44:in `invoke'
from /usr/local/lib/ruby/gems/2.4.0/gems/railties-5.1.3/lib/rails/commands.rb:16:in `<top (required)>'
from /Users/macuser/Desktop/Freelance1/bin/rails:9:in `require'
from /Users/macuser/Desktop/Freelance1/bin/rails:9:in `<top (required)>'
from /usr/local/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
from /usr/local/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
from /usr/local/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
from /usr/local/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
from /usr/local/lib/ruby/gems/2.4.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
from /usr/local/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
from /usr/local/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
from /usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
from /usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
from /Users/macuser/Desktop/Freelance1/bin/spring:15:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
正如我从堆栈跟踪中看到的那样,您缺少此文件:
/Users/macuser/Desktop/Freelance1/config/local_env.yml
这是避免使用git跟踪某些文件的常见模式。例如,database.yml
或secrets.yml
。这些文件通常被添加到.gitignore
,以保存您的凭据,其他机密数据或本地设置,这对其他团队成员私有无用。
这就是为什么有一些示例文件,例如database.example.yml
或secrets.sample.yml
,它们通常都有一个需要在私有文件中填充的字段。
local_env.yml
通常用于为您的应用程序设置一些环境变量(here是一篇关于它的文章)。我想,你的config/application.rb
中有这样的东西:
config.before_configuration do
env_file = File.join(Rails.root, 'config', 'local_env.yml')
YAML.load(File.open(env_file)).each do |key, value|
ENV[key.to_s] = value
end
end
所以它试图打开不存在的文件,你得到这个错误。
检查你的项目,也许有一个local_env.yml
的示例文件。如果没有这样的文件,你可以像这样更改env文件加载:
config.before_configuration do
env_file = File.join(Rails.root, 'config', 'local_env.yml')
YAML.load(File.open(env_file)).each do |key, value|
ENV[key.to_s] = value
end if File.exists?(env_file)
end
所以它会在尝试打开之前检查config/local_env.yml
是否存在。
或者您只需添加一个config/local_env.yml
文件。
但是如果你在这个文件中有一些重要的env变量,你可能会在使用它们的地方出错。但我不认为找到这些地方会是一个问题(至少你可以在你的项目中搜索ENV
来检查env变量的使用位置)并将所需的变量添加到local_env.yml
。