I’m currently playing with Rails 3 (I’m new to rails, coming from PHP
background). Everything works good so far, until yesterday, when I
tried to setup a cronjob.
The most common way to starting regular jobs seems to be using “rails
runner”, right? So, as a test I’ve created a class “Mytest” in /vendor/
Now, when I try to run this method in rails runner like:
shell# rails runner “puts Mytest.hello”
I get this response:
====== snap ==========
lib/rails/commands/runner.rb:45: (eval):1: uninitialized constant
eval' from /Users/christian/.rvm/gems/ruby-1.8.7-p249/gems/ railties-3.0.0.beta/lib/rails/commands/runner.rb:45 from /Users/christian/.rvm/gems/ruby-1.8.7-p249/gems/ railties-3.0.0.beta/lib/rails/commands.rb:60:inrequire’
from /private/tmp/testapp/script/rails:10:in `require’
I was wondering if I did something wrong. So I checked the same stuff
in Rails 2 on another machine. The same call "./script/runner “puts
Mytest.hello” works there.
I did some other test, but the rails runner script seems to throw this
error on other things too (like, when I created a simple model and try
to do "rails runner “User.new”).
The same call in “rails console” does work (in case of “puts
Mytest.hello” prints “hello world”).
Is this a bug in Rails 3? I’m using rvm and tried with serveral ruby
versions (ruby 1.8.7.p29, ruby 1.9.1.p378 and ruby 1.9.2-preview1 and
ruby-head). Rails is “3.0.0.beta”
Any ideas? Did I forget something here (beginner mistake), or is this
a (known) bug?
P.S: I’ve found several ways to working with cron/background jobs with
Rails, like rake, background-rb, rails-runner or delayed_jobs. Is
there any recommended way to do this in Rails 3? I’m just wondering
because I feel cronjobs are a common task in web development, and
usually Rails does have a ‘recommendation’ for common taks.