2012-06-15 15 views
7

मैं रूबी (1.9.3) और रेल (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 

यह देव के साथ ठीक है, लेकिन केवल ऊपर भाग उत्पादन डेटाबेस पर निष्पादित नहीं कर रहा है काम करता है उत्पन्न कर रहा है में से कुछ हिस्सा है। मैं देव पर 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

उत्तर

7

आपका उत्पादन रूबी संस्करण 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 

उत्पादन पर रूबी 1.9.3 इंस्टॉल करें और रैंड विधि अपेक्षित के रूप में कार्य करना चाहिए।

+0

दिलचस्प, रैंड() फ़ंक्शन संदर्भ का उल्लेख नहीं है कि यह एक सीमा को स्वीकार करता है .. http://ruby-doc.org/core-1.9.3/Kernel.html#method-i-rand – MBHNYC

+1

यदि आप उस विवरण में पहली पंक्ति पढ़ते हैं, यह कहता है "यदि अधिकतम रेंज है, तो एक छद्म यादृच्छिक संख्या देता है जहां range.member (संख्या) == सत्य है।" – Chirantan

+0

यह 1.8.7 के लिए यह नहीं कहता (और सही तरीके से स्वीकार नहीं करता है) http://ruby-doc.org/core-1.8.7/Kernel.html#method-i-rand – Chirantan

संबंधित मुद्दे