# Rails 3 - rails runner doesn't work here

**URL:** <https://www.ruby-forum.com/t/rails-3-rails-runner-doesnt-work-here/184268>\
**Category:** Rails\
**Created:** [February 27, 2010, 6:49pm UTC](https://www.ruby-forum.com/t/rails-3-rails-runner-doesnt-work-here/184268 "2010-02-27T18:49:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 27, 2010, 6:49pm UTC](https://www.ruby-forum.com/t/rails-3-rails-runner-doesnt-work-here/184268/1 "2010-02-27T18:49:00Z")

</div>

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:in`require’ 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. 🙂

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 28, 2010, 3:37am UTC](https://www.ruby-forum.com/t/rails-3-rails-runner-doesnt-work-here/184268/2 "2010-02-28T03:37:27Z")

</div>

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 😉

Regards  
Christian
