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.
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"
end
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
lfmthread=Thread.new do
parse_service_1
lfmthread.exit
end
ytthread=Thread.new do
parse_service_2
ytthread.exit
end
end
def parse_service_1
...generate data...
render :update do |page|
page.replace_html :service_1_results, :partial =>
'tag', :object => @tag
end
end
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
you.
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.