以下代码可在本地运行:
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
为什么?
发布于 2013-04-22 11:33:02
原因是方法rand仅在(我相信) 1.9.3之后才开始接受范围值。Heroku使用Ruby 1.9.1。您可以通过查看heroku日志来验证这一点。您只需设计一种方法来使用整数值而不是范围值。
发布于 2013-04-19 03:39:09
确保你在heroku和你的本地开发机器上使用相同版本的ruby:
在本地和heroku上运行ruby -v
:heroku run 'ruby -v'
然后,通过将ruby "1.9.3"
添加到Gemfile来设置ruby heroku使用的版本。
https://stackoverflow.com/questions/16096804
复制