简体   繁体   English

Heroku Rake任务不了解Rand方法

[英]Heroku Rake Task Does Not Understand Rand Method

I have a rake task I created and inside it I have the line 我创建了一个rake任务,并且在其中有一行

number = rand(1..10)

When I run this on my development machine everything is ok, however, when I run it on Heroku I'm returned an error 当我在开发机器上运行它时,一切正常,但是,当我在Heroku上运行它时,我返回了一个错误

rake aborted!
can't convert Range into Integer
/app/lib/tasks/sample_data.rake:57:in `rand'

I should note that earlier in the rake task I ran rand(111) without fail. 我应该注意到,在前耙任务中,我毫无疑问地运行了rand(111) I have to assume the problem is caused by me setting a start and end point for rand to choose from. 我必须假设问题是由我为rand选择的起点和终点引起的。

So the big questions is, why does Heroku treat rand as a range and not as an integer and how do I fix this? 因此,最大的问题是,Heroku为什么将rand视作范围而不是整数,我该如何解决?

Range support in rand() was added in Ruby 1.9.3. Ruby 1.9.3中增加了rand()范围支持。 You're likely running 1.9.2 (the default) on Heroku. 您可能在Heroku上运行1.9.2(默认设置)。 You can run 1.9.3 on Heroku by adding ruby "1.9.3" to your Gemfile. 您可以通过在ruby "1.9.3"添加ruby "1.9.3"在Heroku上运行1.9.3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM