[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: updating an RJS template _while_ executing a method
From: "Matthieu Stone" <matt.stone () cityticketexchange ! com>
Date: 2007-03-31 19:43:45
Message-ID: 00c001c773c8$f3a70050$daf500f0$ () stone () cityticketexchange ! com
[Download RAW message or body]
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.
<script type="text/javascript">
//<![CDATA[
<% if @session[:message] && !@session[:message].blank? %>
poll_message = true;
<% else %>
Poll_message = false;
<% end %>
//]]>
</script>
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.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic