# Juggernaut with backgroundrb

**URL:** <https://www.ruby-forum.com/t/juggernaut-with-backgroundrb/111861>\
**Category:** Rails\
**Created:** [August 12, 2007, 2:42pm UTC](https://www.ruby-forum.com/t/juggernaut-with-backgroundrb/111861 "2007-08-12T14:42:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaffepanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/35a633/32.png) [@kaffepanna](https://www.ruby-forum.com/u/kaffepanna)\
**Post date:** [August 12, 2007, 2:42pm UTC](https://www.ruby-forum.com/t/juggernaut-with-backgroundrb/111861/1 "2007-08-12T14:42:43Z")

</div>

Hej.

Im building a webbased chat client with juggernaut and backgroundrb. The  
idÃ©a was that the client runs on its own process in a worker and acts on  
responses from the actual chat server and then send page updates via  
juggernaut to the appropriate client. This all works fine until i got  
the bright idea (that have now cost me about 2 days of grief) that it  
would be great if i could from the worker render partials to string and  
send them via juggernaut. Since the render\_to\_string method is private  
and only usable in controller classes I wrote this following function

def render\_to\_string(options = nil, &block)  
action\_view = ActionView::Base.new(  
Rails::Configuration.new.view\_path, {},  
MyController.new)  
ActiveSupport::Deprecation.silence { action\_view.render(options,  
&block) }  
end

and made it available to the Worker class. This works to a certain  
extent I can for instance run the following

render\_to\_string :partial =\> ‘my\_superduper\_partial’ :locals =\> {:var =  
“hej hopp”}

but this is kinda useless to me since i need it to be a javscript that i  
send via juggernaut, So In hope of my little function works like the  
original render\_to\_string function i tested

render\_to\_string(:update) do |page|  
page.insert\_html(:bottom, ‘desktop’, ‘hello there’)  
end

And to my amazement it works. So what about inserting partials into the  
javascript

str = render\_to\_string(:update) do |page|  
page.insert\_html(:bottom, ‘desktop’, ":partial =\> ‘my\_partial’)  
end

And there it comes to a grinding halt, the backgroundrb log shows the  
following output

You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.render - (NoMethodError)  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/helpers/prototype\_helper.rb:597:in  
`render' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/helpers/prototype_helper.rb:446:in`insert\_html’  
./script/backgroundrb/…/…/config/…/lib/workers/client\_worker.rb:19:in  
`\_\_bind\_1186927188\_47873

So now im writing here in hope that some one with better understanding  
about rails inner workings can help me…

And yes my hair is getting gray and my girlfriend is yelling at me to  
drop this.

---

<div class="post-metadata">

**Author:** ![kaffepanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/35a633/32.png) [@kaffepanna](https://www.ruby-forum.com/u/kaffepanna)\
**Post date:** [August 12, 2007, 2:45pm UTC](https://www.ruby-forum.com/t/juggernaut-with-backgroundrb/111861/2 "2007-08-12T14:45:13Z")

</div>

Ops slight typo, in the

page.insert\_html(:bottom, ‘desktop’, :partial =\>…

line. that double quote has nothing to do there… still has nothing to  
do with my problem tho ☹

---

<div class="post-metadata">

**Author:** ![kaffepanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/35a633/32.png) [@kaffepanna](https://www.ruby-forum.com/u/kaffepanna)\
**Post date:** [December 18, 2007, 3:33am UTC](https://www.ruby-forum.com/t/juggernaut-with-backgroundrb/111861/3 "2007-12-18T03:33:02Z")

</div>

On Sun, 2007-08-12 at 14:45 +0200, Patrik Pettersson wrote:

> Ops slight typo, in the
> 
> page.insert\_html(:bottom, ‘desktop’, :partial =\>…
> 
> line. that double quote has nothing to do there… still has nothing to  
> do with my problem tho ☹

Are you still on about this? If yes…drop in on backgroundrb mailing  
list and see if we can fix it for ya.

–  
Let them talk of their oriental summer climes of everlasting  
conservatories; give me the privilege of making my own summer with my  
own coals.

[http://gnufied.org](http://gnufied.org)
