Is there any way to update elements of the webpage with multiple threads in an action?

I'm trying to update some elements of the webpage with AJAX, RJS, etc
by making threads in an action of a controller and trying to partial
render the results inside each thread.
The problem is that rails wont let me have more than 1 render or
redirect per action.

Is there any possible way to do this?


This may be enough to get you started.

You can use render :update (though some people will shun you for doing so) and call replace_html multiple times. Something like

render :update do |page|
  page.replace_html 'some_div', :partial => 'some_partial'
  page.replace_html 'some_other_div', :partial => 'some_other_partial'
  page << "some raw javascript if you want"

There are many things you can do with render :update.


I was actually doing that at the begining but id like to do that
render partial in different momtents. Each thread does something and
then they update a certain div in the page. This is more less the code

def parse_services do

      end do


def parse_service_1
      ...generate data...
   render :update do |page|
        page.replace_html :service_1_results, :partial =>
'tag', :object => @tag

Is it possible to do something like this?
Thanks again!

Perhaps rather than calling render from each individual thread, have
each thread send their results to some intermediary object. That
object would then call render only once when it had received all the
data from each thread.

I hope this is relevant. I'm not 100% sure I'm on the same page as

I definitly think that we are on the same page. Its just that an
intermediary object doesn't help since the method of the object is
called from the action itself and we have the same problem.
Thanks again.

This is what I mean:

class Renderer

  def initialize no_of_threads
    @max = no_of_threads
    @count = 0
    @content_to_render = []

  def addContent dom_id, content
    @content_to_render << {:dom_id => dom_id, :content => content}
    if @count == @max

  def output
    render :update do |page|
      @content_to_render.each do |content|
        page.replace_html content[:dom_id], content[:content]


renderer = do
  renderer.addContent :some_dom_id, (render_to_string :partial =>
end do
  renderer.addContent :another_dom_id, "some more generated content"

render_to_string thing not tested - I saw it at