【问题标题】:Array with rand() works locally but not on heroku带有 rand() 的数组在本地工作,但在 heroku 上不工作
【发布时间】:2013-04-22 19:33:02
【问题描述】:

以下在本地工作:

require 'sinatra'

get '/rand' do
  ["one", "two", "three"][rand(0..2)]
end

但是,在 heroku 上,我收到了 Internal Server Error

有趣的是,这是可行的:

get '/rand' do
  ["one", "two", "three"][rand(2) - 1]
end

为什么?

【问题讨论】:

标签: ruby heroku sinatra


【解决方案1】:

确保您在 heroku 和本地开发机器上使用相同版本的 ruby​​:

在本地和 heroku 上运行 ruby -vheroku run 'ruby -v'

然后,通过将ruby "1.9.3" 添加到您的 Gemfile 来设置 ruby​​ heroku 使用的版本。

【讨论】:

    【解决方案2】:

    原因是 rand 方法仅在(我相信) 1.9.3 之后才开始接受范围值。 Heroku 使用 Ruby 1.9.1。您可以通过查看 heroku 日志来验证这一点。您只需要设计一种方法来使用整数值而不是范围值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-02
      • 1970-01-01
      • 1970-01-01
      • 2021-04-26
      • 2013-03-29
      • 2015-02-07
      • 1970-01-01
      • 2014-01-20
      相关资源
      最近更新 更多