简体   繁体   中英

Heroku Rake Task Does Not Understand Rand Method

I have a rake task I created and inside it I have the line

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

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. I have to assume the problem is caused by me setting a start and end point for rand to choose from.

So the big questions is, why does Heroku treat rand as a range and not as an integer and how do I fix this?

Range support in rand() was added in Ruby 1.9.3. You're likely running 1.9.2 (the default) on Heroku. You can run 1.9.3 on Heroku by adding ruby "1.9.3" to your Gemfile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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