Rails 3 - rails runner doesn't work here

Hi,

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/
mytest.rb:

class Mytest
def self.hello
“hello world”
end
end

Now, when I try to run this method in rails runner like:

shell# rails runner “puts Mytest.hello”

I get this response:

====== snap ==========
/Users/christian/.rvm/gems/ruby-1.8.7-p249/gems/railties-3.0.0.beta/
lib/rails/commands/runner.rb:45: (eval):1: uninitialized constant
Mytest (NameError)
from /Users/christian/.rvm/gems/ruby-1.8.7-p249/gems/
railties-3.0.0.beta/lib/rails/commands.rb:60:in 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 /Users/christian/.rvm/gems/ruby-1.8.7-p249/gems/
railties-3.0.0.beta/lib/rails/commands.rb:60
from /private/tmp/testapp/script/rails:10:in `require’
from /private/tmp/testapp/script/rails:10

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?

Regards,
Christian

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. :slight_smile:

Hm, seems to be a problem in the older rails beta (the one you install
with ‘gem install rails --pre’).
With rails -v => Rails 3.0.0.beta1 the error disappears :wink:

Regards
Christian

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs