meefster-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2010-Feb-27 17:47 UTC
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: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.
:-)
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
meefster-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2010-Feb-28 02:34 UTC
Re: Rails 3 - rails runner doesn''t work here
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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.