8

I am using Ruby (1.9.3) and Rails (3.2.2). I have tasks file which contains a bunch of fake data to be populated to my database.

Here is some part of the task that I believe is causing the problem

#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

It works fine with dev but only the above part is not executed on production database. I am using gem 'sqlite3', '1.3.5' on dev. and

gem 'pg', '0.12.2' on production (heroku)

When I run

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.**

Any ideas what the problem might be?

EDIT: The data type of bid_amount is decimal

1 Answer 1

8

Your production ruby version is not 1.9.3. It is probably 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 

Install ruby 1.9.3 on production and the rand method should work as expected.

Sign up to request clarification or add additional context in comments.

11 Comments

Interesting, the rand() function reference doesn't mention it accepts a range at all.. ruby-doc.org/core-1.9.3/Kernel.html#method-i-rand
If you read the first line in that description, it says "If max is Range, returns a pseudorandom number where range.member(number) == true."
Thank you for your response. How do you install ruby on heroku even I dont know a way to know the version on the production server. I thought it is already installed on heroku.Sorry, I am learning ruby.
And I am using Git on windows
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.