Does anyone know if it''s possible to do multiple AJAX responses to a single request in Rails? I did some googling but didn''t find anything extremely helpful. 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bob wrote:> Does anyone know if it''s possible to do multiple AJAX responses to a > single request in Rails? I did some googling but didn''t find anything > extremely helpful.What do you mean? One HTTP request gets one response. That''s the way the protocol works> > Thanks.Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
On 10 Feb 2010, at 17:18, Marnen Laibow-Koser wrote:>> Does anyone know if it''s possible to do multiple AJAX responses to a >> single request in Rails? I did some googling but didn''t find >> anything >> extremely helpful. > > What do you mean? One HTTP request gets one response. That''s the way > the protocol worksIndeed, every HTTP request only yields one response. What you are looking for is a PeriodicalExecuter or PeriodicalUpdater (javascript polling every xx seconds). Another way to go is a push notification system, which is more difficult to implement and host (forget about hosting it on a shared host). Juggernaut or Comet should help you out there. But unless you really know what you are doing, the periodical execution way is going to give you the least amount of problems. Best regards Peter De Berdt -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I have a class that compares invoice totals for a month and calculates the dollars saved. The downside is it takes about 1 second per invoice per month to calculate so it''s taking a considerable amount of time to display a complete report especially if you run it for a two year period (48 seconds). What I was hoping to do is to make an AJAX request for the report and respond with each row (or month in this case) of the comparison table as they finish calculating. I had a feeling this would be pretty problematic to do... On Feb 10, 11:29 am, Peter De Berdt <peter.de.be...-LPO8gxj9N8aZIoH1IeqzKA@public.gmane.org> wrote:> On 10 Feb 2010, at 17:18, Marnen Laibow-Koser wrote: > > >> Does anyone know if it''s possible to do multiple AJAX responses to a > >> single request in Rails? I did some googling but didn''t find > >> anything > >> extremely helpful. > > > What do you mean? One HTTP request gets one response. That''s the way > > the protocol works > > Indeed, every HTTP request only yields one response. What you are > looking for is a PeriodicalExecuter or PeriodicalUpdater (javascript > polling every xx seconds). Another way to go is a push notification > system, which is more difficult to implement and host (forget about > hosting it on a shared host). Juggernaut or Comet should help you out > there. But unless you really know what you are doing, the periodical > execution way is going to give you the least amount of problems. > > Best regards > > Peter De Berdt-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
In my opinion, there''s three ways to go about this: 1. Pregenerate reports in low traffic/low CPU usage times, like overnight. Since you are making monthly invoicing reports, the reports should stay the same anyway. When the user requests a certain range, assemble the cached pieces into on nice report. 2. Fire a PeriodicalExecuter to a controller method. The first time, it starts the report generation in a background process, every subsequent request will load the generated report lines into the view 3. Use Juggernaut or Comet to push the data to the client. Fire an event to start the report generation in a background process and then route to the clients that are subscribed to the right Juggernaut/Comet channel. Personally, unless realtime reports are an absolute necessity, I would just go for a nightly report generation cron tab. It will provide the best experience to your end user and won''t put a serious strain on the server overall during peak traffic times. On 10 Feb 2010, at 20:08, Bob wrote:> I have a class that compares invoice totals for a month and calculates > the dollars saved. The downside is it takes about 1 second per > invoice per month to calculate so it''s taking a considerable amount of > time to display a complete report especially if you run it for a two > year period (48 seconds). What I was hoping to do is to make an AJAX > request for the report and respond with each row (or month in this > case) of the comparison table as they finish calculating. I had a > feeling this would be pretty problematic to do... > > > On Feb 10, 11:29 am, Peter De Berdt <peter.de.be...-LPO8gxj9N8aZIoH1IeqzKA@public.gmane.org> wrote: >> On 10 Feb 2010, at 17:18, Marnen Laibow-Koser wrote: >> >>>> Does anyone know if it''s possible to do multiple AJAX responses >>>> to a >>>> single request in Rails? I did some googling but didn''t find >>>> anything >>>> extremely helpful. >> >>> What do you mean? One HTTP request gets one response. That''s the >>> way >>> the protocol works >> >> Indeed, every HTTP request only yields one response. What you are >> looking for is a PeriodicalExecuter or PeriodicalUpdater (javascript >> polling every xx seconds). Another way to go is a push notification >> system, which is more difficult to implement and host (forget about >> hosting it on a shared host). Juggernaut or Comet should help you out >> there. But unless you really know what you are doing, the periodical >> execution way is going to give you the least amount of problems.Best regards Peter De Berdt -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.