7
我正在使用Ruby(1.9.3)和Rails(3.2.2)。我有任務文件,其中包含一些假數據將填充到我的數據庫。無法將範圍轉換爲整數(Ruby on Rails)
這裏是我認爲是造成問題
#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
它正常工作與開發,但只有在生產數據庫中不執行上述部分任務的某些部分。我在dev上使用gem 'sqlite3', '1.3.5'
。並在生產
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.**
任何想法的問題可能是什麼?
編輯: BID_AMOUNT的數據類型是decimal
有趣的是,rand()函數的引用沒有提及它接受範圍.. http://ruby-doc.org/core-1.9.3/Kernel.html#method-i-rand – MBHNYC
如果您在該描述中讀取第一行,它說:「如果max是Range,則返回一個僞隨機數,其中range.member(number)== true。」 – Chirantan
對於1.8.7 http://ruby-doc.org/core-1.8.7/Kernel.html#method-i-和 – Chirantan