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.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---