无法将Range转换为Integer(Ruby on Rails)

Wow*_*Bow 7 ruby range heroku ruby-on-rails-3

我正在使用Ruby(1.9.3)和Rails(3.2.2).我有任务文件,其中包含要填充到我的数据库的一堆虚假数据.

以下是我认为导致问题的部分任务

#Create random Tender and populate the db
     20.times do |n|
      title  = "#{Faker::Company.bs()} tender "
      company_name = Faker::Company.name
      opening_date=Time.at(rand * Time.now.to_i)
      closing_date=Time.at(opening_date + ( 8*7*24*60*60)) #add 8 weeks to the deadline
      bid_amount= rand(10000..100000)
      description=Faker::Lorem.paragraph(sentence_count = 3)


      Tender.create!(title: title,
                   company_name: company_name,
                   opening_date: opening_date,
                   closing_date: closing_date,
           bid_amount: bid_amount    ,
           bid_amount: bid_amount    ,
           description: description )
    end
Run Code Online (Sandbox Code Playgroud)

它适用于dev,但只有上述部分不在生产数据库上执行.我gem 'sqlite3', '1.3.5'在dev上使用 .和

gem 'pg', '0.12.2' 在生产(heroku)

我跑的时候

git push heroku
$ heroku pg:reset SHARED_DATABASE --confirm myapp
$ heroku run rake db:migrate
$ heroku run rake db:populate

db:populate throws an error that says **can't covert Range to Integer.**
Run Code Online (Sandbox Code Playgroud)

任何想法可能是什么问题?

编辑: bid_amount的数据类型是decimal

Chi*_*tan 7

您的生产ruby版本不是1.9.3.大概是1.8.7

$ ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
$ irb
>> rand(10000..100000)
TypeError: can't convert Range into Integer
    from (irb):1:in `rand'
    from (irb):1
>> exit
$ rvm use 1.9.3
Using /Users/chirantan/.rvm/gems/ruby-1.9.3-p0
$ irb
1.9.3p0 :001 > rand(10000..100000)
 => 37036 
Run Code Online (Sandbox Code Playgroud)

在生产中安装ruby 1.9.3并且rand方法应该按预期工作.

  • 任何方式谢谢.http://blog.heroku.com/archives/2012/5/9/multiple_ruby_version_support_on_heroku/ (3认同)