# \[Help\] How to pass multiple arguments to a method in a worker?

**URL:** <https://www.ruby-forum.com/t/help-how-to-pass-multiple-arguments-to-a-method-in-a-worker/147608>\
**Category:** Rails\
**Created:** [September 3, 2008, 4:54pm UTC](https://www.ruby-forum.com/t/help-how-to-pass-multiple-arguments-to-a-method-in-a-worker/147608 "2008-09-03T16:54:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hao\_Liu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8c91f0/32.png) [@Hao\_Liu](https://www.ruby-forum.com/u/Hao_Liu)\
**Post date:** [September 3, 2008, 4:54pm UTC](https://www.ruby-forum.com/t/help-how-to-pass-multiple-arguments-to-a-method-in-a-worker/147608/1 "2008-09-03T16:54:53Z")

</div>

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](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 =\>  
‘removed\_email\_address@domain.invalid’, :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

---

<div class="post-metadata">

**Author:** ![Hao\_Liu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8c91f0/32.png) [@Hao\_Liu](https://www.ruby-forum.com/u/Hao_Liu)\
**Post date:** [September 3, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/help-how-to-pass-multiple-arguments-to-a-method-in-a-worker/147608/2 "2008-09-03T17:06:02Z")

</div>

Hao Liu wrote:

> MiddleMan.worker(:hard\_worker).send\_mail(:args =\> {:recipient =\>  
> ‘removed\_email\_address@domain.invalid’, :subject =\> ‘BlahBlah’})

Just send the parameters as a single hash:

send\_mail(:recipient =\> ‘removed\_email\_address@domain.invalid’, :subject =\> ‘BlahBlah’)

–  
Rails Wheels - Find Plugins, List & Sell Plugins -  
[http://railswheels.com](http://railswheels.com)
