Hao Liu
2008-Sep-03 09:06 UTC
[Backgroundrb-devel] [Help] How to pass multiple arguments to a method in a worker?
Hi, guys,
I ran into a problem while I tried to pass more than one parameters to
a method in the worker class, it fails, from the backgroundrb log, I
found that:
You have a nil object when you didn''t expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
Seems the args is nil, but a hash I passed in my controller. From the
post:
http://rubyforge.org/pipermail/backgroundrb-devel/2008-April/001668.html,
it should be a hash if there are multiple arguments. Here''s what I did:
In my controller:
def blah
MiddleMan.worker(:hard_worker).send_mail(:args => {:recipient =>
''blahblah at gmail.com'', :subject =>
''BlahBlah''})
end
In my worker class:
def send_mail(args)
emailer.send_mail(args[:recipient], args[:subject])
end
Is there anything wrong?
Additional info:
ruby-1.8.6
backgroundrb 1.0.4
All the best,
Hao Liu
hemant kumar
2008-Sep-03 10:50 UTC
[Backgroundrb-devel] [Help] How to pass multiple arguments to a method in a worker?
On Wed, 2008-09-03 at 17:06 +0800, Hao Liu wrote:> Hi, guys, > I ran into a problem while I tried to pass more than one parameters to > a method in the worker class, it fails, from the backgroundrb log, I > found that: > > You have a nil object when you didn''t expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.[] > > Seems the args is nil, but a hash I passed in my controller. From the > post: > http://rubyforge.org/pipermail/backgroundrb-devel/2008-April/001668.html, > it should be a hash if there are multiple arguments. Here''s what I did: > > In my controller: > def blah > MiddleMan.worker(:hard_worker).send_mail(:args => {:recipient => > ''blahblah at gmail.com'', :subject => ''BlahBlah''}) > end > > In my worker class: > def send_mail(args) > emailer.send_mail(args[:recipient], args[:subject]) > endErr, because its ":arg" not ":args" , hence: MiddleMan.worker(:hard_worker).send_mail(:arg => {:recipient => ''blahblah at gmail.com'', :subject => ''BlahBlah''}) I thought, I had it documented here: http://backgroundrb.rubyforge.org/rails/