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
Related
I'm trying to develop a ruby gem for practice and I'm wondering how do I require pry during development and test runs? Is there anyway to require the gem only during development? I'm on Ruby and not Rails and I don't think I have any environment variables setup to rely on. Is there a conventional way to do this?
and
Currently if I run code that hits the above line, I get this error:
NoMethodError: undefined method `pry' for #<Binding:0x007f8d3287c4d8>
from /Users/jwan/programming/interview_questions/gemini/jobcoin_client/lib/jobcoin_client/requests/connection.rb:18:in `post'
A few questions:
How do I properly require pry so this line doesn't throw an error when developing a gem?
I read Yahuda's post but I'm still unclear why adding dependencies in the gemspec vs adding dependencies in the Gemfile. What is the difference?
Currently, after I make changes to the ruby gem, I have to run these series of commands. Is there anything more efficient that I can do?
gem build jobcoin_client.gemspec
WARNING: no homepage specified
WARNING: open-ended dependency on pry (>= 0, development) is not recommended
if pry is semantically versioned, use:
add_development_dependency 'pry', '~> 0'
WARNING: See http://guides.rubygems.org/specification-reference/ for help
Successfully built RubyGem
Name: jobcoin_client
Version: 0.1.0
File: jobcoin_client-0.1.0.gem
$ gem install jobcoin_client
Successfully installed jobcoin_client-0.1.0
Parsing documentation for jobcoin_client-0.1.0
Done installing documentation for jobcoin_client after 0 seconds
1 gem installed
05:45 PM
$ irb
irb(main):001:0> require 'jobcoin_client'
=> true
irb(main):002:0> require 'pry'
=> false
You can install it to the system and use a boolean flag to conditionally require it and set breakpoints.
gem install pry
Then in code, something like this:
SET_BREAKPOINTS = ENV["SET_BREAKPOINTS"] == "true"
require 'pry' if SET_BREAKPOINTS
binding.pry if SET_BREAKPINTS
To turn breakpoints on, you can manipulate env through code:
ENV["SET_BREAKPOINTS"] = "true"
or when calling a script from bash:
env SET_BREAKPOINTS=true irb -r 'your_gem'
I have a legacy Rails application which I want to upgrade to recent Rails and Ruby versions.To start with I am trying to setup the application with Ruby 2.1.2
$ rails -v
Rails 2.3.18
$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [i686-linux]
When I tried to run the rake task rake db:schema:load RAILS_ENV=test I encountered following error
can not load translations from /activesupport-2.3.18/lib/active_support/locale/en.yml, the file type yml is not known
Searching through Google I found the following reference https://github.com/rails/rails/issues/10514 which mentioned that there is incompatibility between Rails 2.3 and Ruby 2+ versions.
Can anybody please help me applying a monkey-patch mentioned about in the reference link?
Thanks,
Jignesh
Finally resolved the error
can not load translations from /activesupport-2.3.18/lib/active_support/locale/en.yml, the file type yml is not known
by monkey-patching the Rails’s I18n::Backend::Base#load_file(filename) method.
The solution is as follows:
1.1 Created a file named ruby2.rb at /config/initializers
1.2 Added following contents to /config/initializers/ruby2.rb
if Rails::VERSION::MAJOR == 2 && RUBY_VERSION >= '2.0.0'
module I18n
module Backend
module Base
def load_file(filename)
type = File.extname(filename).tr('.', '').downcase
# As a fix added second argument as true to respond_to? method
raise UnknownFileType.new(type, filename) unless respond_to?(:"load_#{type}", true)
data = send(:"load_#{type}", filename) # TODO raise a meaningful exception if this does not yield a Hash
data.each { |locale, d| store_translations(locale, d) }
end
end
end
end
end
1.3 Finally ran
$ rake db:schema:load RAILS_ENV=test
and the schema was successfully loaded.
Most helpful references I could find and which helped me get to the solution:
https://github.com/rails/rails/issues/10514
https://www.lucascaton.com.br/2014/02/28/have-a-rails-2-app-you-can-run-it-on-the-newest-ruby/
When I run bundle exec guard after upgrading to Ruby 2.1.1, I get this:
Frame number: 0/1
before_session hook failed: NotImplementedError: NotImplementedError
/home/eric/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/interception-0.4/lib/interception.rb:122:in `start'
(see _pry_.hooks.errors to debug)
How can I resolve this?
The officially released version of the interception gem you are using (0.4) checks for MRI Ruby 2.1 via the following method:
# lib/interception.rb
def self.ruby_21?
RUBY_VERSION == '2.1.0' && RUBY_ENGINE == 'ruby'
end
Obviously, this fails for Ruby 2.1.1
This is corrected in the master branch (https://github.com/ConradIrwin/interception), but the correction has not been released to RubyGems (as of 3/5/14).
Edit:
As of 3/6/14, interception v0.5 has been released to RubyGems and fixes this issue. Verify the interception gem is not set to v0.4 or lower in your Gemfile, then run bundle update interception.
Heroku Deploy for Rails app is failing currently. I am getting the following error message. I haven't changed any gems or rails code but just changed some static HTML and CSS files.
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.0.0
-----> Installing dependencies using 1.5.2
Ruby version change detected. Clearing bundler cache.
Old: ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
New: ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
sh: Syntax error: EOF in backquote substitution
sh: Syntax error: EOF in backquote substitution
/app/tmp/buildpacks/ruby/lib/language_pack/ruby.rb:760:in `block in purge_bundler_cache': undefined local variable or method `install_language_pack_gems' for #<LanguagePack::Rails4:0x00000001974ab8> (NameError)
This is Heroku's fault. Perhaps just some caching issue, but maybe they just broke something. Anyway, the solution is to set the BUILDPACK_URL for your app to point to the latest Ruby Heroku buildpack:
heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-ruby -a <app-name>
Try this from the command line. I think you're upgrading versions and somehow aren't pointing to the correct buildpack.
heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack
More info here: https://devcenter.heroku.com/articles/buildpacks
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.