Javier Quevedo
2008-Jan-01 20:56 UTC
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? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Phillip Koebbe
2008-Jan-01 21:11 UTC
Re: Is there any way to update elements of the webpage with multiple threads in an action?
On Jan 1, 2008, at 2:56 PM, Javier Quevedo wrote:> > 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" end There are many things you can do with render :update. Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Javier Quevedo
2008-Jan-01 21:23 UTC
Re: Is there any way to update elements of the webpage with multiple threads in an action?
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! On Jan 1, 10:11 pm, Phillip Koebbe <phillipkoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jan 1, 2008, at 2:56 PM, Javier Quevedo wrote: > > > > > 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" > end > > There are many things you can do with render :update. > > Peace, > Phillip--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
LemmingJoel
2008-Jan-01 22:17 UTC
Re: Is there any way to update elements of the webpage with multiple threads in an action?
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. On Jan 2, 8:23 am, Javier Quevedo <jquev...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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! > > On Jan 1, 10:11 pm, Phillip Koebbe <phillipkoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Jan 1, 2008, at 2:56 PM, Javier Quevedo wrote: > > > > 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" > > end > > > There are many things you can do with render :update. > > > Peace, > > Phillip- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Javier Quevedo
2008-Jan-01 22:59 UTC
Re: Is there any way to update elements of the webpage with multiple threads in an action?
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. On Jan 1, 11:17 pm, LemmingJoel <joel.pl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > On Jan 2, 8:23 am, Javier Quevedo <jquev...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > 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! > > > On Jan 1, 10:11 pm, Phillip Koebbe <phillipkoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Jan 1, 2008, at 2:56 PM, Javier Quevedo wrote: > > > > > 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" > > > end > > > > There are many things you can do with render :update. > > > > Peace, > > > Phillip- Hide quoted text - > > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
LemmingJoel
2008-Jan-01 23:24 UTC
Re: Is there any way to update elements of the webpage with multiple threads in an action?
This is what I mean: class Renderer def initialize no_of_threads @max = no_of_threads @count = 0 @content_to_render = [] end def addContent dom_id, content @content_to_render << {:dom_id => dom_id, :content => content} @count++ if @count == @max output end end def output render :update do |page| @content_to_render.each do |content| page.replace_html content[:dom_id], content[:content] end end end end renderer = Renderer.new(2) thread1=Thread.new do renderer.addContent :some_dom_id, (render_to_string :partial => "name_of_partial") end thread2=Thread.new do renderer.addContent :another_dom_id, "some more generated content" end render_to_string thing not tested - I saw it at http://snippets.dzone.com/posts/show/396 On Jan 2, 9:59 am, Javier Quevedo <jquev...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > On Jan 1, 11:17 pm, LemmingJoel <joel.pl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > 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. > > > On Jan 2, 8:23 am, Javier Quevedo <jquev...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > 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! > > > > On Jan 1, 10:11 pm, Phillip Koebbe <phillipkoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Jan 1, 2008, at 2:56 PM, Javier Quevedo wrote: > > > > > > 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" > > > > end > > > > > There are many things you can do with render :update. > > > > > Peace, > > > > Phillip- Hide quoted text - > > > > - Show quoted text -- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---