From: ruby-talk@... Date: 2007-04-02T19:16:54+09:00 Subject: Re: updating an RJS template _while_ executing a method Hey Matt, what I still don't understand is where to turn "poll_message" on and off using your JS-code? Or: what do you mean with "...in a RJS update..."? -> Inside the RJS-template of "my_io_process"? That throws quite a few errors. -> Using inline RJS rendering inside my controller? (which shouldn't work while also using an RJS template) -> somewhere else..? Also: Do I need to specify a ":update => 'my_div'" within periodically_call_remote? When I put this call inside my layout, Firebug yells at me: "poll_message not defined"... Is a "var poll_message = false" fine? Thanks for your help! Cheers, Tom. --------------------------------- On Sun, 1 Apr 2007 04:43:45 +0900 "Matthieu Stone" wrote: > Here's one way > > In your method doing the IO stuff, update a session variable with the > message that you want displayed; ie: > > def my_io_process > session[:message] = "Starting..." > do something > session[:message] = "Updated message" > do something else.. etc > session[:message] = nil > end > > > Create another controller method that just returns the value of > session[:message]. > > def update_message > render :text => session[:message]; :layout => false > end > > So now, all you need is a periodic routine that updates a div on the page > with the session[:message] contents. You can either update the div directly > from this call, or like I do, use RJS to do other things on the page. This > polling is turned on & off by the javascript variable poll_message > > <%= periodically_call_remote( > :condition => "poll_message == true", > :frequency => 2, > :url => { :action => 'update_message', :only_path => false } > ) %> > > > You can turn poll_message on & off like this, just include this code in a > RJS update whenever you want to change turn the polling on & off. > > > > > Rgds, > - matt. > > -----Original Message----- > From: ruby-talk@hinv.org [mailto:ruby-talk@hinv.org] > Sent: 31 March 2007 17:56 > To: ruby-talk ML > Subject: updating an RJS template _while_ executing a method > > I have a method doing I/O stuff which takes quite a long time. > While this method is processed, > I want the user of my tool to be informed of the current execution state. > > For example, > if the method opens a file, > I want my RJS template to render a message such as "opening file XYZ...", > if the method changes to a directory, message would be "cd to ...". > > As far as I can tell, > RJS templates are rendered AFTER the corresponding method is executed. > But I want them to run (sort of) synchronously. > Or at least have a way to trigger messages while a method is executed. > > Cheers, > Tom. > >