Rails 服务器错误 secret_key

Rails 服务器错误 secret_key

我在 ruby​​mine 中使用 ruby​​ on rails 创建了一个应用程序。我在 Windows 电脑上制作了它,它运行正常。现在我把它转移到装有 Ubuntu 的电脑上,我用这个安装了 ubuntu教程。现在,当我在 localhost:3000 上调用 rails 服务器并在浏览器中转到该页面时出现错误。

Puma caught this error: Missing `secret_key_base` for 'development' environment, set this value in `config/secrets.yml` (RuntimeError)
/home/fangio/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/application.rb:513:in `validate_secret_key_config!'
/home/fangio/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/application.rb:246:in `env_config'
/home/fangio/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/engine.rb:693:in `build_request'
/home/fangio/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/application.rb:521:in `build_request'
/home/fangio/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/engine.rb:521:in `call'
/home/fangio/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.8.2/lib/puma/configuration.rb:224:in `call'
/home/fangio/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.8.2/lib/puma/server.rb:600:in `handle_request'
/home/fangio/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.8.2/lib/puma/server.rb:435:in `process_client'
/home/fangio/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.8.2/lib/puma/server.rb:299:in `block in run'
/home/fangio/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.8.2/lib/puma/thread_pool.rb:120:in `block in spawn_thread'

我该如何轻松修复此问题?我是 Ubuntu 新手。

答案1

它清楚地说明了缺少什么以及在哪里。您需要打开“config/secrets.yml”并添加开发环境的密钥

您可以使用 irb 生成随机密钥:

irb
irb(main):001:0> require 'securerandom'
=> true
irb(main):002:0> SecureRandom.hex(64)
=>"6bb7bc01dd219ac9f074c26c4016260349f70d90f0c38ae171f2232a844bac54c0d6c6bae50eecdbcc73c828bd68076a5700449d069dc8e1ad5a43abd9386dca"

irb(主要):003:0>

然后将那串长字符串复制到秘密文件中

相关内容