Juggernaut with backgroundrb

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:ininsert_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.

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 :frowning:

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 :frowning:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs