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
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.
Related
When trying to use byebug for the first time with ruby 2.2.3 I get
NameError:
undefined local variable or method `byebug'
I'm confused, here's are some diagnostics:
ruby --version
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
cat Gemfile | grep bye
gem 'byebug'
gem list | grep bye
byebug (8.2.1, 8.2.0)
#the command I'm using to run my ruby code is
rspec *spec.rb --tag focus
#also tried prepending bundle exec
Figure it out. I needed this line:
require 'byebug'; byebug;
in my ruby code.
did you run bundle install on your app (assuming this is in the context of a rails app given that you're using Gemfiles)?
Edit: you figured it out, I see :D I was going to suggest requiring the library next but I see that I didn't need to.
I'm having a really strange issue. On my remote server (which is a Max OSX Server), I have Ruby 1.9.3 installed via RVM. When I type ruby -v, I get
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin12.3.0]
When I type in which bundle, I get
/Users/moby/.rvm/gems/ruby-1.9.3-p448/bin/bundle
And if I do bundle install in my Rails project, it succeeds without any errors.
However, when I try with Capistrano via cap deploy:cold on my local machine, which SSH's into the remote machine, deployment fails with the following error:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:777:in
`report_activate_error': Could not find RubyGem bundler (>= 0)
(Gem::LoadError)
Why is it using Ruby 1.8? How do I get it to use Ruby 1.9.3 instead?
I was able to solve the issue by doing the following:
SSH into your remote server, and print out the following values:
$PATH
$RUBY_VERSION
$GEM_HOME
$GEM_PATH
$BUNDLE_PATH
Add the following entry into the deploy.rb file, setting the values of each key to the respective outputs from above:
set :default_environment, {
'PATH' => "/Users/USERNAME/.rvm/gems/ruby-1.9.3-p448/bin:/Users/USERNAME/.rvm/gems/ruby-1.9.3-p448#global/bin:/Users/USERNAME/.rvm/rubies/ruby-1.9.3-p448/bin:/Users/USERNAME/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin:/usr/local/git/bin",
"RUBY_VERSION" => "ruby 1.9.3",
"GEM_HOME" => "/Users/USERNAME/.rvm/gems/ruby-1.9.3-p448",
"GEM_PATH" => "/Users/USERNAME/.rvm/gems/ruby-1.9.3-p448:/Users/OraServer1Admin/.rvm/gems/ruby-1.9.3-p448#global",
"BUNDLE_PATH" => "/Users/USERNAME/.rvm/gems/ruby-1.9.3-p448/bin/bundle"
}
sudo update-alternatives --config gem
and select the right version
I'm trying to push an app to heroku using "git push heroku master".
In my Gemfile, I have the following:
source 'https://rubygems.org'
ruby 'ruby 1.9.3'
gem 'foreman'
but when I try to push to heroku, I get the following error:
! Invalid RUBY_VERSION specified: Gemfile-syntax-error:-<!DOCTYPE-html>-^-/tmp/build_o93twnijmxig/Gemfile:5:-syntax-error,-unexpected-'<'-<html>-^-/tmp/build_o93twnijmxig/Gemfile:7:-syntax-error,-unexpected-'<'-<meta-charset='utf-8'>-^-/tmp/build_o93twnijmxig/Gemfile:8:-syntax-error,-unexpected-'<'-<meta-http-equiv="X-UA-Compatible"-content="IE=edge">-^-/tmp/build_o93twnijmxig/Gemfile:8:-syntax-error,-unexpected-tIDENTIFIER,-expecting-$end-<meta-http-equiv="X-UA-Compatible"-content="IE=edge">-^
! Valid versions: ruby-1.9.3-p0, ruby-1.9.3-p125, rbx-1.2.4, rbx-2.0.0dev-20120115-1.9, rbx-2.0.0dev-20120115-1.8, rbx-2.0.0dev-20120123-1.9, rbx-2.0.0dev-20120123-1.8, ruby-1.9.2-p290, jruby-1.6.5.1, jruby-1.6.7, ruby-1.9.3, ruby-1.9.2, ruby-1.8.7, ruby-1.9.3-jruby-1.7.0.preview1, ruby-1.8.7-jruby-1.7.0.preview1, ruby-1.9.3-rbx-2.0.0dev, ruby-1.8.7-rbx-2.0.0dev
!
! Heroku push rejected, failed to compile Ruby app
When I enter: heroku config -s | grep PATH
I get the following output:
PATH=bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin
and running: heroku run "ruby -v" ,outputs:
Running `ruby -v` attached to terminal... up, run.1
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
But when I try to run bundle install in the app directory, I get this strange message:
Your Ruby version is 1.9.3, but your Gemfile specified ruby 1.9.3
source 'https://rubygems.org'
ruby '1.9.3'
gem 'foreman'
I am trying to write a simple Ruby program that I will run from my computer to check/set the amount of dynos I have running on my Heroku app. I am doing this because the highest frequency you can run cron in a Heroku app is hourly, and I want more frequent checking of the queue depth.
This simple Ruby app will exist outside of the actual Ruby on Rails application. In order to check/set the dynos, I need to use the Heroku gem. The gem is already installed as a local gem
$ gem list heroku
*** LOCAL GEMS ***
heroku (1.16.2, 1.9.8)
How can I access the Heroku gem from my simple Ruby app? I have tried:
dynos_check.rb
require 'heroku'
But I get this error when I try to run it:
$ ruby dynos_check.rb
dynos_check.rb:1:in `require': no such file to load -- heroku (LoadError)
from dynos_check.rb:1
How can I access the Heroku gem?
Here is some other info:
$ which ruby
/usr/local/bin/ruby
$ gem env | grep 'RUBY EXECUTABLE'
- RUBY EXECUTABLE: /usr/local/bin/ruby
You didn't say what version of Ruby you're running, but if it's < 1.9, before all other require statements, you'll need to add:
require 'rubygems'
Ruby 1.9+ does that automatically.
Here's the error:
>> Delayed::Job.find(:last).last_error
=> {Job failed to load: uninitialized constant Syck::Syck. Handler: \"--- !ruby/struct:Delayed::PerformableMethod \\nobject: &id007 !ruby/object:TryController \\n _action_name: create
but I have syck ext installed.
Usage:
def create_user(name,pass,time)
puts "hello"
Net::HTTP.get(URI.parse("http://www.example.net/buildtest.php?hao=#{name}&mi=#{pass}&da=#{time}"))
end
def create
delay.create_user("nihao000oei9","1","1")
end
gem 'delayed_job', '2.1.4'
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
Rails 3.0.1
thanks.
I found this as an issue when I upgraded from Rails 2 to 3 and deployed to the Heroku Cedar stack. It's an issue when Delayed_Job attempts to deserialise the handler from the Job queue item. By default it uses the Syck YAML parser.
Turns out Syck isn't available on the Heroku Cedar stack.
Including the Psych gem and redeploying fixed it for me and allow me to re-invoke the failed jobs.
gem 'psych'
I just ran into this and it turned out to be a syntax error in my just-modified database.yml.
It was using a bad reference for cucumber:
test: &test
database: test
cucumber:
<<: &base