2017-09-01 53 views
0

所以我犯了一個巨大的錯誤,就是從git中刪除一個rails應用程序並將其克隆。現在我堅持不讓我的服務器使用rails s運行。無法用rails使用rails啓動數據庫s

我不斷收到以下錯誤,我不知道如何解決它。

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>' 
+0

你使用git嗎? – 7urkm3n

回答

0

當我從堆棧跟蹤看,你缺少這個文件:

/Users/macuser/Desktop/Freelance1/config/local_env.yml 

這是一個常見的模式,以避免跟蹤一些文件與GIT。例如,database.ymlsecrets.yml。通常會將這些文件添加到.gitignore,以保留您的憑據,另一個機密數據或只是本地設置,這對於其他團隊成員而言是私有的。

這就是爲什麼有示例文件,如database.example.ymlsecrets.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