No Method Error on any task except the built in CRUD methods?

7 views
Skip to first unread message

Darin-murray

unread,
Sep 8, 2009, 9:33:15 PM9/8/09
to Whenever Gem

I_am trying to set up a cron job with whenever gem. All is installed
ok, and deployment works.
But I can't get script/runner to execute anything outside of the
normal built in CRUD actions.

Example, I can run script/runner "Request.create", and it successfully
creates a new request in the db. However, when I try to run script/
runner "Request.sendit", it returns "undefined method `sendit' for
#<Class:0x1033a1750> (NoMethodError)"

The method works from the browser, ie. requests/sendit does in fact
execute the action.

I have tried random models and methods, and only the build in CRUD
action work. Anything else gets ( as one example):
runner.rb:47: undefined method `email_update' for UserMailer:Class
(NoMethodError)

What am I doing wrong here?
THanks in advance!
Darin

Javan Makhmali

unread,
Sep 17, 2009, 9:31:15 PM9/17/09
to whenev...@googlegroups.com
Hey Darin, I think, perhaps, you're confused about what script/
runner's actually execute. It's not the same as an incomming http
request to your app. So script/runner "Request.sendit" has nothing to
do with requesting /requests/sendit in a browser.

I think most often people use runners to execute class methods in
their models. For example, if you have this model:

class Request < ActiveRecord::Base
def self.my_class_method
# some code to execute
end
end

could be executed with a runner like: script/runner
"Request.my_class_method"

Hope that helps!

Javan

bobo

unread,
Oct 25, 2009, 3:33:38 PM10/25/09
to Whenever Gem
Hi Darin,
I had similar issues and struggled for ages to find out what was
wrong.

Make sure your methods are on Models (not controllers) and they are
defined with "self." in front of the method, this will make it work
without an instantiated object.

so if your model is 'Ticket' and your method is 'send', then in
ticket.rb:

def send
... your stuff
end

does NOT work

def self.send
... your stuff
end

DOES work.

Hope it helps you or someone else

bobo
Reply all
Reply to author
Forward
0 new messages