【问题标题】:Heroku version not set despite following guide尽管遵循以下指南,但未设置 Heroku 版本
【发布时间】:2016-10-31 06:17:01
【问题描述】:

我正在尝试将 rails 5 应用程序推送到 Heroku,并且我相信我遵循了 Heroku 页面上的说明: https://devcenter.heroku.com/articles/ruby-versions

$ ruby --version
ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]

$ cat Gemfile
.....
ruby "2.3.1"

$ heroku run bash
$ env | grep PATH
PATH=/app/bin:/usr/local/bin:/usr/bin:/bin

$ git push heroku master
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.2.4

以错误终止:

remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        rake aborted!
remote:        NoMethodError: undefined method `symbolize_keys' for #       <String:0x007fac0655feb0>
remote:           /tmp/build_39bfaebc9acd5a6bcb91a69f2b13c171/vendor/bundle/ruby/2.2.0/gems /railties-5.0.0.1/lib/rails/application.rb:393:in `secrets'

我猜是因为它使用的是 2.2 而不是 2.3。

/bin 中的版本是 1.9.3,所以如果找不到,它应该使用 1.9.3 而不是 2.2.4。

上面的错误信息已在 spickermann 的帮助下得到修复。从 git 跟踪中删除 secret.yml 文件后,应用可以顺利部署。

仍然存在错误的 Ruby 版本,Heroku 甚至在最后返回警告:

remote: ###### WARNING:
remote:        You have not declared a Ruby version in your Gemfile.
remote:        To set your Ruby version add this line to your Gemfile:
remote:        ruby '2.2.4'
remote:        # See https://devcenter.heroku.com/articles/ruby-     versions for more information.

还有什么可以做的建议吗?

谢谢!

【问题讨论】:

  • 我忘了说 bin/bundle 和指南中的完全一样
  • $ bundler --version Bundler 版本 1.13.6

标签: ruby-on-rails ruby heroku


【解决方案1】:

您的部署失败,因为您的 config/secret.yml 不是预期的格式。它期望在生产环境中有这样的嵌套哈希:

production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

您的config/secrets.yml 为键production 返回一个字符串。因此部署失败,您永远无法部署新版本。

【讨论】:

  • 感谢 spickermann 的回复。按照您的建议,我发现问题确实出在 secret.yml 文件上。不过原因有点不同。虽然格式很好,但它不应该被 git 跟踪。显然,由 git 跟踪的 secret.yml 可能会导致此错误发生。尽管如此,ruby 版本仍然是 2.2.4。我什至现在得到一个警告,我的 Gemfile 应该包含这个字符串。它确实包含 2.3.1。会不会是Gemfile被忽略了?
  • 它在哪里包含该字符串?在source 定义正下方的第二行顶部?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-01-04
  • 1970-01-01
  • 1970-01-01
  • 2011-06-09
  • 1970-01-01
  • 1970-01-01
  • 2021-12-30
相关资源
最近更新 更多