# Where have Ruby/Tk examples gone?

**URL:** <https://rubytalk.org/t/where-have-ruby-tk-examples-gone/36590>\
**Category:** ruby-talk\
**Created:** [31 March 2007 16:08 UTC](https://rubytalk.org/t/where-have-ruby-tk-examples-gone/36590 "2007-03-31T16:08:03Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Morton\_Goldberg](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@Morton\_Goldberg](https://rubytalk.org/u/Morton_Goldberg)\
**Post date:** [31 March 2007 16:08 UTC](https://rubytalk.org/t/where-have-ruby-tk-examples-gone/36590/1 "2007-03-31T16:08:03Z")

</div>

I have previously been able to access Hidetoshi NAGAI's examples of Ruby/Tk code with the following URL:

&nbsp;&nbsp;&nbsp;&nbsp;[http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/ext/tk/sample/](http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/ext/tk/sample/)

Now I'm getting a 404 Not Found error when I point my browser there. I think this happens because the CVS archives are no longer available. However, I can't find equivalent examples in the SVN archives. Does anybody know where these examples can now be found?

Regards, Morton

---

<div class="post-metadata">

**Author:** ![Tom\_V](https://avatars.discourse-cdn.com/v4/letter/t/c6cbf5/32.png) [@Tom\_V](https://rubytalk.org/u/Tom_V)\
**Post date:** [31 March 2007 16:56 UTC](https://rubytalk.org/t/where-have-ruby-tk-examples-gone/36590/2 "2007-03-31T16:56:00Z")

</div>

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,  
&nbsp;&nbsp;Tom.

---

<div class="post-metadata">

**Author:** ![Hidetoshi\_NAGAI](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@Hidetoshi\_NAGAI](https://rubytalk.org/u/Hidetoshi_NAGAI)\
**Post date:** [3 April 2007 10:13 UTC](https://rubytalk.org/t/where-have-ruby-tk-examples-gone/36590/3 "2007-04-03T10:13:43Z")

</div>

Message-ID: \<3AA0EEA8-82F5-4DE9-917A-81104B37C304@ameritech.net\>

> I have previously been able to access Hidetoshi NAGAI's examples of  
> Ruby/Tk code with the following URL:

&nbsp;&nbsp;&nbsp;(snip)

> archives. Does anybody know where these examples can now be found?

[http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby\_1\_8/ext/tk/sample/](http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ext/tk/sample/)

> **···**
>
> From: Morton Goldberg \<m\_goldberg@ameritech.net\>  
> Subject: Where have Ruby/Tk examples gone?  
> Date: Sun, 1 Apr 2007 01:08:03 +0900
> 
> --  
> Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

---

<div class="post-metadata">

**Author:** ![Matthieu\_Stone](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@Matthieu\_Stone](https://rubytalk.org/u/Matthieu_Stone)\
**Post date:** [31 March 2007 19:43 UTC](https://rubytalk.org/t/where-have-ruby-tk-examples-gone/36590/4 "2007-03-31T19:43:45Z")

</div>

Here's one way

In your method doing the IO stuff, update a session variable with the  
message that you want displayed; ie:

&nbsp;&nbsp;def my\_io\_process  
&nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "Starting..."  
&nbsp;&nbsp;&nbsp;&nbsp;do something  
&nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "Updated message"  
&nbsp;&nbsp;&nbsp;&nbsp;do something else.. etc  
&nbsp;&nbsp;&nbsp;&nbsp;session[:message] = nil  
&nbsp;&nbsp;end

Create another controller method that just returns the value of  
session[:message].

&nbsp;&nbsp;def update\_message  
&nbsp;&nbsp;&nbsp;&nbsp;render :text =\> session[:message]; :layout =\> false  
&nbsp;&nbsp;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(  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:condition =\> "poll\_message == true",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:frequency =\> 2,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:url =\> { :action =\> 'update\_message', :only\_path =\> false }  
&nbsp;&nbsp;&nbsp;&nbsp;) %\>

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.

&nbsp;&nbsp;\<script type="text/javascript"\>  
&nbsp;&nbsp;//\<![CDATA[  
&nbsp;&nbsp;&nbsp;&nbsp;\<% if @session[:message] && !@session[:message].blank? %\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;poll\_message = true;  
&nbsp;&nbsp;&nbsp;&nbsp;\<% else %\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Poll\_message = false;  
&nbsp;&nbsp;&nbsp;&nbsp;\<% end %\>  
&nbsp;&nbsp;//]]\>  
&nbsp;&nbsp;\</script\>

Rgds,  
- matt.

> **···**
>
> -----Original Message-----  
> From: [ruby-talk@hinv.org](mailto:ruby-talk@hinv.org) [[mailto: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,  
> &nbsp;&nbsp;Tom.

---

<div class="post-metadata">

**Author:** ![Tom\_V](https://avatars.discourse-cdn.com/v4/letter/t/c6cbf5/32.png) [@Tom\_V](https://rubytalk.org/u/Tom_V)\
**Post date:** [2 April 2007 10:16 UTC](https://rubytalk.org/t/where-have-ruby-tk-examples-gone/36590/5 "2007-04-02T10:16:54Z")

</div>

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,  
&nbsp;&nbsp;Tom.

> **···**
>
> ---------------------------------  
> On Sun, 1 Apr 2007 04:43:45 +0900 "Matthieu Stone" \<matt.stone@cityticketexchange.com\> wrote:
> 
> > Here's one way
> > 
> > In your method doing the IO stuff, update a session variable with the  
> > message that you want displayed; ie:
> > 
> > &nbsp;&nbsp;def my\_io\_process  
> > &nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "Starting..."  
> > &nbsp;&nbsp;&nbsp;&nbsp;do something  
> > &nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "Updated message"  
> > &nbsp;&nbsp;&nbsp;&nbsp;do something else.. etc  
> > &nbsp;&nbsp;&nbsp;&nbsp;session[:message] = nil  
> > &nbsp;&nbsp;end
> > 
> > Create another controller method that just returns the value of  
> > session[:message].
> > 
> > &nbsp;&nbsp;def update\_message  
> > &nbsp;&nbsp;&nbsp;&nbsp;render :text =\> session[:message]; :layout =\> false  
> > &nbsp;&nbsp;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(  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:condition =\> "poll\_message == true",  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:frequency =\> 2,  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:url =\> { :action =\> 'update\_message', :only\_path =\> false }  
> > &nbsp;&nbsp;&nbsp;&nbsp;) %\>
> > 
> > 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.
> > 
> > &nbsp;&nbsp;\<script type="text/javascript"\>  
> > &nbsp;&nbsp;//\<![CDATA[  
> > &nbsp;&nbsp;&nbsp;&nbsp;\<% if @session[:message] && !@session[:message].blank? %\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;poll\_message = true;  
> > &nbsp;&nbsp;&nbsp;&nbsp;\<% else %\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Poll\_message = false;  
> > &nbsp;&nbsp;&nbsp;&nbsp;\<% end %\>  
> > &nbsp;&nbsp;//]]\>  
> > &nbsp;&nbsp;\</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,  
> > &nbsp;&nbsp;Tom.

---

<div class="post-metadata">

**Author:** ![Morton\_Goldberg](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@Morton\_Goldberg](https://rubytalk.org/u/Morton_Goldberg)\
**Post date:** [3 April 2007 15:26 UTC](https://rubytalk.org/t/where-have-ruby-tk-examples-gone/36590/6 "2007-04-03T15:26:43Z")

</div>

Thank you very much for supplying the URL I was looking for.

Regards, Morton

> **···**
>
> On Apr 3, 2007, at 6:13 AM, Hidetoshi NAGAI wrote:
> 
> > From: Morton Goldberg \<m\_goldberg@ameritech.net\>  
> > Subject: Where have Ruby/Tk examples gone?  
> > Date: Sun, 1 Apr 2007 01:08:03 +0900  
> > Message-ID: \<3AA0EEA8-82F5-4DE9-917A-81104B37C304@ameritech.net\>
> > 
> > > I have previously been able to access Hidetoshi NAGAI's examples of  
> > > Ruby/Tk code with the following URL:
> > 
> > &nbsp;&nbsp;&nbsp;(snip)
> > 
> > > archives. Does anybody know where these examples can now be found?
> > 
> > [http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby\_1\_8/ext/tk/sample/](http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ext/tk/sample/)

---

<div class="post-metadata">

**Author:** ![Matthieu\_Stone](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@Matthieu\_Stone](https://rubytalk.org/u/Matthieu_Stone)\
**Post date:** [2 April 2007 10:57 UTC](https://rubytalk.org/t/where-have-ruby-tk-examples-gone/36590/7 "2007-04-02T10:57:54Z")

</div>

Hi Tom,

I think that this will answer your questions.

To get rid of the firebug message, just make sure that this routine

> \<div id="poll\_message"\>\<%= session[:message] %\>\</div\>  
> &nbsp;&nbsp;\<script type="text/javascript"\>  
> &nbsp;&nbsp;//\<![CDATA[  
> &nbsp;&nbsp;&nbsp;&nbsp;\<% if @session[:message] && !@session[:message].blank? %\>  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;poll\_message = true;  
> &nbsp;&nbsp;&nbsp;&nbsp;\<% else %\>  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Poll\_message = false;  
> &nbsp;&nbsp;&nbsp;&nbsp;\<% end %\>  
> &nbsp;&nbsp;//]]\>  
> &nbsp;&nbsp;\</script\>

Is rendered in the page before the periodically\_call\_update routine, it's  
easier to place this in a partial, then you can it via RJS in any controller  
method. I've added the poll\_message div to make things a little more  
explicit.

&nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "let's get it started.."

&nbsp;&nbsp;&nbsp;&nbsp;respond\_to do |format|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.js { render :update do |page|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page.replace 'poll\_message', :partial =\>  
'poll\_message'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page.visual\_effect :highlight, 'poll\_message',  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:duration =\> 1,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:startcolor =\> '"#FFCCFF"',  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:endcolor =\> '"#FFFFCC"'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;end

I use the respond\_to mechanism to update div's on the page, rather than .rjs  
files. I don't need to specify :update =\> some\_div in the  
periodically\_call\_remote routine & I can do other things, such as highlight  
the updated message or update another part of the screen using logic in the  
controller. There are upsides & downsides to doing things this way, I just  
find it easier to do it in the controller as it keeps all my page logic in  
the one place.

rgds,  
- matt.

> **···**
>
> -----Original Message-----  
> From: ruby-talk@hinv.org [mailto:ruby-talk@hinv.org]  
> Sent: 02 April 2007 11:17  
> To: ruby-talk ML  
> 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,  
> &nbsp;&nbsp;Tom.
> 
> ---------------------------------  
> On Sun, 1 Apr 2007 04:43:45 +0900 "Matthieu Stone" \<matt.stone@cityticketexchange.com\> wrote:
> 
> > Here's one way
> > 
> > In your method doing the IO stuff, update a session variable with the  
> > message that you want displayed; ie:
> > 
> > &nbsp;&nbsp;def my\_io\_process  
> > &nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "Starting..."  
> > &nbsp;&nbsp;&nbsp;&nbsp;do something  
> > &nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "Updated message"  
> > &nbsp;&nbsp;&nbsp;&nbsp;do something else.. etc  
> > &nbsp;&nbsp;&nbsp;&nbsp;session[:message] = nil  
> > &nbsp;&nbsp;end
> > 
> > Create another controller method that just returns the value of  
> > session[:message].
> > 
> > &nbsp;&nbsp;def update\_message  
> > &nbsp;&nbsp;&nbsp;&nbsp;render :text =\> session[:message]; :layout =\> false  
> > &nbsp;&nbsp;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(  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:condition =\> "poll\_message == true",  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:frequency =\> 2,  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:url =\> { :action =\> 'update\_message', :only\_path =\> false }  
> > &nbsp;&nbsp;&nbsp;&nbsp;) %\>
> > 
> > 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.
> > 
> > &nbsp;&nbsp;\<script type="text/javascript"\>  
> > &nbsp;&nbsp;//\<![CDATA[  
> > &nbsp;&nbsp;&nbsp;&nbsp;\<% if @session[:message] && !@session[:message].blank? %\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;poll\_message = true;  
> > &nbsp;&nbsp;&nbsp;&nbsp;\<% else %\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Poll\_message = false;  
> > &nbsp;&nbsp;&nbsp;&nbsp;\<% end %\>  
> > &nbsp;&nbsp;//]]\>  
> > &nbsp;&nbsp;\</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,  
> > &nbsp;&nbsp;Tom.

---

<div class="post-metadata">

**Author:** ![Tom\_V](https://avatars.discourse-cdn.com/v4/letter/t/c6cbf5/32.png) [@Tom\_V](https://rubytalk.org/u/Tom_V)\
**Post date:** [2 April 2007 14:14 UTC](https://rubytalk.org/t/where-have-ruby-tk-examples-gone/36590/8 "2007-04-02T14:14:13Z")

</div>

Hi Matt,

As you suggested I put the "poll\_message"-div + JS-code + periodically\_...  
inside a partial rendered at startup.

I also got rid of the RJS-template in exchange for your "respond\_to" thing  
But here is the thing:  
my io\_process-method looks sort of like this:

def io\_method  
&nbsp;&nbsp;session[:message] = "starting io..."  
&nbsp;&nbsp;# ...  
&nbsp;&nbsp;if (blah)  
&nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "finished"  
&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "an error occurred!"  
&nbsp;&nbsp;end  
&nbsp;&nbsp;respond\_to do |format|  
&nbsp;&nbsp;&nbsp;&nbsp;format.js { render :update do |page|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page.insert\_html :bottom, 'poll\_message', :partial =\> 'message'  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;}  
&nbsp;&nbsp;session[:message] = nil  
end

my partial "\_message.rhtml" just calls "\<%= session[:message] %\>"

So when the interpreter gets to "respond\_to",  
it only renders the last message defined by the io\_method.

Also the message is rendered after io\_method is done.  
So I am actually where I started from:  
the template messages get rendered after the controller method is done.

Thanks for your help!

Cheers,  
&nbsp;&nbsp;Tom.

> **···**
>
> ---------------------------------  
> On Mon, 2 Apr 2007 19:57:54 +0900 "Matthieu Stone" \<matt.stone@cityticketexchange.com\> wrote:
> 
> > Hi Tom,
> > 
> > I think that this will answer your questions.
> > 
> > To get rid of the firebug message, just make sure that this routine
> > 
> > \>\<div id="poll\_message"\>\<%= session[:message] %\>\</div\>  
> > \> \<script type="text/javascript"\>  
> > \> //\<![CDATA[  
> > \> \<% if @session[:message] && !@session[:message].blank? %\>  
> > \> poll\_message = true;  
> > \> \<% else %\>  
> > \> Poll\_message = false;  
> > \> \<% end %\>  
> > \> //]]\>  
> > \> \</script\>
> > 
> > Is rendered in the page before the periodically\_call\_update routine, it's  
> > easier to place this in a partial, then you can it via RJS in any controller  
> > method. I've added the poll\_message div to make things a little more  
> > explicit.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "let's get it started.."
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;respond\_to do |format|  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.js { render :update do |page|  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page.replace 'poll\_message', :partial =\>  
> > 'poll\_message'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page.visual\_effect :highlight, 'poll\_message',  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:duration =\> 1,  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:startcolor =\> '"#FFCCFF"',  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:endcolor =\> '"#FFFFCC"'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
> > &nbsp;&nbsp;&nbsp;&nbsp;end
> > 
> > I use the respond\_to mechanism to update div's on the page, rather than .rjs  
> > files. I don't need to specify :update =\> some\_div in the  
> > periodically\_call\_remote routine & I can do other things, such as highlight  
> > the updated message or update another part of the screen using logic in the  
> > controller. There are upsides & downsides to doing things this way, I just  
> > find it easier to do it in the controller as it keeps all my page logic in  
> > the one place.
> > 
> > rgds,  
> > - matt.
> > 
> > -----Original Message-----  
> > From: ruby-talk@hinv.org [mailto:ruby-talk@hinv.org]  
> > Sent: 02 April 2007 11:17  
> > To: ruby-talk ML  
> > 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,  
> > &nbsp;&nbsp;Tom.
> > 
> > ---------------------------------  
> > On Sun, 1 Apr 2007 04:43:45 +0900 \> "Matthieu Stone" \<matt.stone@cityticketexchange.com\> 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.  
> > \>  
> > \> \<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.  
> > \>  
> > \>

---

<div class="post-metadata">

**Author:** ![Matthieu\_Stone](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@Matthieu\_Stone](https://rubytalk.org/u/Matthieu_Stone)\
**Post date:** [2 April 2007 16:21 UTC](https://rubytalk.org/t/where-have-ruby-tk-examples-gone/36590/9 "2007-04-02T16:21:35Z")

</div>

Ah.. In that case you need to start you long running routine outside of  
rails. Something like backgroundrb, [http://backgroundrb.rubyforge.org/](http://backgroundrb.rubyforge.org/)

> **···**
>
> -----Original Message-----  
> From: ruby-talk@hinv.org [mailto:ruby-talk@hinv.org]  
> Sent: 02 April 2007 15:14  
> To: ruby-talk ML  
> Subject: Re: updating an RJS template \_while\_ executing a method
> 
> Hi Matt,
> 
> As you suggested I put the "poll\_message"-div + JS-code + periodically\_...  
> inside a partial rendered at startup.
> 
> I also got rid of the RJS-template in exchange for your "respond\_to" thing  
> But here is the thing:  
> my io\_process-method looks sort of like this:
> 
> def io\_method  
> &nbsp;&nbsp;session[:message] = "starting io..."  
> &nbsp;&nbsp;# ...  
> &nbsp;&nbsp;if (blah)  
> &nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "finished"  
> &nbsp;&nbsp;else  
> &nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "an error occurred!"  
> &nbsp;&nbsp;end  
> &nbsp;&nbsp;respond\_to do |format|  
> &nbsp;&nbsp;&nbsp;&nbsp;format.js { render :update do |page|  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page.insert\_html :bottom, 'poll\_message', :partial =\> 'message'  
> &nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;}  
> &nbsp;&nbsp;session[:message] = nil  
> end
> 
> my partial "\_message.rhtml" just calls "\<%= session[:message] %\>"
> 
> So when the interpreter gets to "respond\_to",  
> it only renders the last message defined by the io\_method.
> 
> Also the message is rendered after io\_method is done.  
> So I am actually where I started from:  
> the template messages get rendered after the controller method is done.
> 
> Thanks for your help!
> 
> Cheers,  
> &nbsp;&nbsp;Tom.
> 
> ---------------------------------  
> On Mon, 2 Apr 2007 19:57:54 +0900 "Matthieu Stone" \<matt.stone@cityticketexchange.com\> wrote:
> 
> > Hi Tom,
> > 
> > I think that this will answer your questions.
> > 
> > To get rid of the firebug message, just make sure that this routine
> > 
> > \>\<div id="poll\_message"\>\<%= session[:message] %\>\</div\>  
> > \> \<script type="text/javascript"\>  
> > \> //\<![CDATA[  
> > \> \<% if @session[:message] && !@session[:message].blank? %\>  
> > \> poll\_message = true;  
> > \> \<% else %\>  
> > \> Poll\_message = false;  
> > \> \<% end %\>  
> > \> //]]\>  
> > \> \</script\>
> > 
> > Is rendered in the page before the periodically\_call\_update routine, it's  
> > easier to place this in a partial, then you can it via RJS in any
> 
> controller
> 
> > method. I've added the poll\_message div to make things a little more  
> > explicit.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "let's get it started.."
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;respond\_to do |format|  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.js { render :update do |page|  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page.replace 'poll\_message', :partial =\>  
> > 'poll\_message'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page.visual\_effect :highlight, 'poll\_message',  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:duration =\> 1,  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:startcolor =\> '"#FFCCFF"',  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:endcolor =\> '"#FFFFCC"'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
> > &nbsp;&nbsp;&nbsp;&nbsp;end
> > 
> > I use the respond\_to mechanism to update div's on the page, rather than
> 
> .rjs
> 
> > files. I don't need to specify :update =\> some\_div in the  
> > periodically\_call\_remote routine & I can do other things, such as
> 
> highlight
> 
> > the updated message or update another part of the screen using logic in
> 
> the
> 
> > controller. There are upsides & downsides to doing things this way, I just  
> > find it easier to do it in the controller as it keeps all my page logic in  
> > the one place.
> > 
> > rgds,  
> > - matt.
> > 
> > -----Original Message-----  
> > From: ruby-talk@hinv.org [mailto:ruby-talk@hinv.org]  
> > Sent: 02 April 2007 11:17  
> > To: ruby-talk ML  
> > 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,  
> > &nbsp;&nbsp;Tom.
> > 
> > ---------------------------------  
> > On Sun, 1 Apr 2007 04:43:45 +0900 \> "Matthieu Stone" \<matt.stone@cityticketexchange.com\> 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.  
> > \>  
> > \> \<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.  
> > \>  
> > \>

---

<div class="post-metadata">

**Author:** ![Ryan\_Leavengood](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@Ryan\_Leavengood](https://rubytalk.org/u/Ryan_Leavengood)\
**Post date:** [2 April 2007 16:37 UTC](https://rubytalk.org/t/where-have-ruby-tk-examples-gone/36590/10 "2007-04-02T16:37:18Z")

</div>

This is what we do in the Rails app I'm working on. We call a long  
running series of SOAP API calls from BackgrounDRb and then a periodic  
executor on the page calls a "progress" function which queries the  
BackgrounDrb worker to get the current progress. This works pretty  
well.

Though I was very annoyed to see the latest version of BackgrounDrb is  
not supported on Windows. We deploy on Linux but develop on Windows so  
we are stuck on the last release. If you are listening Ezra, it would  
be nice if you could fix this 🙂

Ryan

> **···**
>
> On 4/2/07, Matthieu Stone \<matt.stone@cityticketexchange.com\> wrote:
> 
> > Ah.. In that case you need to start you long running routine outside of  
> > rails. Something like backgroundrb, [http://backgroundrb.rubyforge.org/](http://backgroundrb.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![Jeremy\_McAnally1](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@Jeremy\_McAnally1](https://rubytalk.org/u/Jeremy_McAnally1)\
**Post date:** [3 April 2007 01:42 UTC](https://rubytalk.org/t/where-have-ruby-tk-examples-gone/36590/11 "2007-04-03T01:42:21Z")

</div>

My suggestion: run your task using BackgrounDrb or something similar.  
Use periodically\_call\_remote to poll the execution's status until it's  
completed.

--Jeremy

> **···**
>
> On 4/2/07, ruby-talk@hinv.org \<ruby-talk@hinv.org\> wrote:
> 
> > Hi Matt,
> > 
> > As you suggested I put the "poll\_message"-div + JS-code + periodically\_...  
> > inside a partial rendered at startup.
> > 
> > I also got rid of the RJS-template in exchange for your "respond\_to" thing  
> > But here is the thing:  
> > my io\_process-method looks sort of like this:
> > 
> > def io\_method  
> > &nbsp;&nbsp;session[:message] = "starting io..."  
> > &nbsp;&nbsp;# ...  
> > &nbsp;&nbsp;if (blah)  
> > &nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "finished"  
> > &nbsp;&nbsp;else  
> > &nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "an error occurred!"  
> > &nbsp;&nbsp;end  
> > &nbsp;&nbsp;respond\_to do |format|  
> > &nbsp;&nbsp;&nbsp;&nbsp;format.js { render :update do |page|  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page.insert\_html :bottom, 'poll\_message', :partial =\> 'message'  
> > &nbsp;&nbsp;&nbsp;&nbsp;end  
> > &nbsp;&nbsp;}  
> > &nbsp;&nbsp;session[:message] = nil  
> > end
> > 
> > my partial "\_message.rhtml" just calls "\<%= session[:message] %\>"
> > 
> > So when the interpreter gets to "respond\_to",  
> > it only renders the last message defined by the io\_method.
> > 
> > Also the message is rendered after io\_method is done.  
> > So I am actually where I started from:  
> > the template messages get rendered after the controller method is done.
> > 
> > Thanks for your help!
> > 
> > Cheers,  
> > &nbsp;&nbsp;Tom.
> > 
> > ---------------------------------  
> > On Mon, 2 Apr 2007 19:57:54 +0900 \> "Matthieu Stone" \<matt.stone@cityticketexchange.com\> wrote:
> > 
> > \> Hi Tom,  
> > \>  
> > \> I think that this will answer your questions.  
> > \>  
> > \> To get rid of the firebug message, just make sure that this routine  
> > \>  
> > \> \>\<div id="poll\_message"\>\<%= session[:message] %\>\</div\>  
> > \> \> \<script type="text/javascript"\>  
> > \> \> //\<![CDATA[  
> > \> \> \<% if @session[:message] && !@session[:message].blank? %\>  
> > \> \> poll\_message = true;  
> > \> \> \<% else %\>  
> > \> \> Poll\_message = false;  
> > \> \> \<% end %\>  
> > \> \> //]]\>  
> > \> \> \</script\>  
> > \>  
> > \> Is rendered in the page before the periodically\_call\_update routine, it's  
> > \> easier to place this in a partial, then you can it via RJS in any controller  
> > \> method. I've added the poll\_message div to make things a little more  
> > \> explicit.  
> > \>  
> > \> session[:message] = "let's get it started.."  
> > \>  
> > \> respond\_to do |format|  
> > \> format.js { render :update do |page|  
> > \> page.replace 'poll\_message', :partial =\>  
> > \> 'poll\_message'  
> > \> page.visual\_effect :highlight, 'poll\_message',  
> > \> :duration =\> 1,  
> > \> :startcolor =\> '"#FFCCFF"',  
> > \> :endcolor =\> '"#FFFFCC"'  
> > \> end  
> > \> }  
> > \> end  
> > \>  
> > \> I use the respond\_to mechanism to update div's on the page, rather than .rjs  
> > \> files. I don't need to specify :update =\> some\_div in the  
> > \> periodically\_call\_remote routine & I can do other things, such as highlight  
> > \> the updated message or update another part of the screen using logic in the  
> > \> controller. There are upsides & downsides to doing things this way, I just  
> > \> find it easier to do it in the controller as it keeps all my page logic in  
> > \> the one place.  
> > \>  
> > \> rgds,  
> > \> - matt.  
> > \>  
> > \> -----Original Message-----  
> > \> From: ruby-talk@hinv.org [mailto:ruby-talk@hinv.org]  
> > \> Sent: 02 April 2007 11:17  
> > \> To: ruby-talk ML  
> > \> 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" \<matt.stone@cityticketexchange.com\> 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.  
> > \> \>  
> > \> \> \<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.  
> > \> \>  
> > \>
> 
> --  
> [http://www.jeremymcanally.com/](http://www.jeremymcanally.com/)
> 
> My free Ruby e-book:  
> [http://www.humblelittlerubybook.com/book/](http://www.humblelittlerubybook.com/book/)
> 
> My blogs:
> 
> > **[Site not found · DreamHost](http://www.mrneighborly.com/)**
> >
> > The owner of this domain has not yet uploaded their website.
> 
> [http://www.rubyinpractice.com/](http://www.rubyinpractice.com/)

---

<div class="post-metadata">

**Author:** ![Tom\_V](https://avatars.discourse-cdn.com/v4/letter/t/c6cbf5/32.png) [@Tom\_V](https://rubytalk.org/u/Tom_V)\
**Post date:** [16 April 2007 09:45 UTC](https://rubytalk.org/t/where-have-ruby-tk-examples-gone/36590/12 "2007-04-16T09:45:56Z")

</div>

If anyone still cares...

I just used the callbacks available for link\_to\_remote, form\_remote\_tag etc...  
It works well and easy to use:

\<%= image\_tag("ajax-loader-darkblue.gif" , :id =\> 'loader', :style =\> 'display:none') %\>  
\<%= content\_tag(:div, content\_tag(:p, "An error occurred. Please try again"), :id =\> 'failure', :class =\> 'strong', :style =\> 'display:none') %\>

\<div id="project\_name"\>  
&nbsp;&nbsp;\<% form\_remote\_tag(:url =\> {:action =\> :create\_project, :id =\> @project},  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:loading =\> "Element.show('loader');  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Element.hide('project\_name')",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:failure =\> "Element.show('failure')") do %\>  
&nbsp;&nbsp;&nbsp;&nbsp;\<p\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<label for="project\_p\_name"\>Project Name:&nbsp;\</label\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= text\_field 'project', 'p\_name' %\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= submit\_tag "create" %\>  
&nbsp;&nbsp;&nbsp;&nbsp;\</p\>  
&nbsp;&nbsp;\<% end %\>  
\</div\>

> **···**
>
> On Tue, 3 Apr 2007 01:21:35 +0900 "Matthieu Stone" \<matt.stone@cityticketexchange.com\> wrote:
> 
> > Ah.. In that case you need to start you long running routine outside of  
> > rails. Something like backgroundrb, [http://backgroundrb.rubyforge.org/](http://backgroundrb.rubyforge.org/)
> > 
> > -----Original Message-----  
> > From: ruby-talk@hinv.org [mailto:ruby-talk@hinv.org]  
> > Sent: 02 April 2007 15:14  
> > To: ruby-talk ML  
> > Subject: Re: updating an RJS template \_while\_ executing a method
> > 
> > Hi Matt,
> > 
> > As you suggested I put the "poll\_message"-div + JS-code + periodically\_...  
> > inside a partial rendered at startup.
> > 
> > I also got rid of the RJS-template in exchange for your "respond\_to" thing  
> > But here is the thing:  
> > my io\_process-method looks sort of like this:
> > 
> > def io\_method  
> > &nbsp;&nbsp;session[:message] = "starting io..."  
> > &nbsp;&nbsp;# ...  
> > &nbsp;&nbsp;if (blah)  
> > &nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "finished"  
> > &nbsp;&nbsp;else  
> > &nbsp;&nbsp;&nbsp;&nbsp;session[:message] = "an error occurred!"  
> > &nbsp;&nbsp;end  
> > &nbsp;&nbsp;respond\_to do |format|  
> > &nbsp;&nbsp;&nbsp;&nbsp;format.js { render :update do |page|  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page.insert\_html :bottom, 'poll\_message', :partial =\> 'message'  
> > &nbsp;&nbsp;&nbsp;&nbsp;end  
> > &nbsp;&nbsp;}  
> > &nbsp;&nbsp;session[:message] = nil  
> > end
> > 
> > my partial "\_message.rhtml" just calls "\<%= session[:message] %\>"
> > 
> > So when the interpreter gets to "respond\_to",  
> > it only renders the last message defined by the io\_method.
> > 
> > Also the message is rendered after io\_method is done.  
> > So I am actually where I started from:  
> > the template messages get rendered after the controller method is done.
> > 
> > Thanks for your help!
> > 
> > Cheers,  
> > &nbsp;&nbsp;Tom.
> > 
> > ---------------------------------  
> > On Mon, 2 Apr 2007 19:57:54 +0900 \> "Matthieu Stone" \<matt.stone@cityticketexchange.com\> wrote:
> > 
> > \> Hi Tom,  
> > \>  
> > \> I think that this will answer your questions.  
> > \>  
> > \> To get rid of the firebug message, just make sure that this routine  
> > \>  
> > \> \>\<div id="poll\_message"\>\<%= session[:message] %\>\</div\>  
> > \> \> \<script type="text/javascript"\>  
> > \> \> //\<![CDATA[  
> > \> \> \<% if @session[:message] && !@session[:message].blank? %\>  
> > \> \> poll\_message = true;  
> > \> \> \<% else %\>  
> > \> \> Poll\_message = false;  
> > \> \> \<% end %\>  
> > \> \> //]]\>  
> > \> \> \</script\>  
> > \>  
> > \> Is rendered in the page before the periodically\_call\_update routine, it's  
> > \> easier to place this in a partial, then you can it via RJS in any  
> > controller  
> > \> method. I've added the poll\_message div to make things a little more  
> > \> explicit.  
> > \>  
> > \> session[:message] = "let's get it started.."  
> > \>  
> > \> respond\_to do |format|  
> > \> format.js { render :update do |page|  
> > \> page.replace 'poll\_message', :partial =\>  
> > \> 'poll\_message'  
> > \> page.visual\_effect :highlight, 'poll\_message',  
> > \> :duration =\> 1,  
> > \> :startcolor =\> '"#FFCCFF"',  
> > \> :endcolor =\> '"#FFFFCC"'  
> > \> end  
> > \> }  
> > \> end  
> > \>  
> > \>  
> > \> I use the respond\_to mechanism to update div's on the page, rather than  
> > .rjs  
> > \> files. I don't need to specify :update =\> some\_div in the  
> > \> periodically\_call\_remote routine & I can do other things, such as  
> > highlight  
> > \> the updated message or update another part of the screen using logic in  
> > the  
> > \> controller. There are upsides & downsides to doing things this way, I just  
> > \> find it easier to do it in the controller as it keeps all my page logic in  
> > \> the one place.  
> > \>  
> > \> rgds,  
> > \> - matt.  
> > \>  
> > \> -----Original Message-----  
> > \> From: ruby-talk@hinv.org [mailto:ruby-talk@hinv.org]  
> > \> Sent: 02 April 2007 11:17  
> > \> To: ruby-talk ML  
> > \> 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" \<matt.stone@cityticketexchange.com\> 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.  
> > \> \>  
> > \> \> \<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.  
> > \> \>  
> > \> \>  
> > \>  
> > \>

---

<div class="post-metadata">

**Author:** ![Ezra\_Zygmuntowicz](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@Ezra\_Zygmuntowicz](https://rubytalk.org/u/Ezra_Zygmuntowicz)\
**Post date:** [2 April 2007 23:14 UTC](https://rubytalk.org/t/where-have-ruby-tk-examples-gone/36590/13 "2007-04-02T23:14:53Z")

</div>

Ryan-

&nbsp;&nbsp;I'd love to be able to get the new version to run on windows but I wasn't ever able to get it to work except for in cygwin. The reason being is the new version uses a multi process arch instead of a single process multi threaded. I rely heavily on ara's slave gem for this which handles forking child processes with drb handles from the parent -\> child and child -\> parent. As far as I know slave just can't work on windows yet.

&nbsp;&nbsp;I will however soon be releasing a bdrb lite that is a revamped version of the old plugin that will be windows compatible. It's just inherently limited by ruby's green threading model. So running many concurrent jobs degrades the performance of all jobs 😕

&nbsp;&nbsp;I would love to be proven wrong and shown how I could get the newest version with the slave dep to run on windows though.

Cheers-  
-- Ezra Zygmuntowicz-- Lead Rails Evangelist  
-- ez@engineyard.com  
-- Engine Yard, Serious Rails Hosting  
-- (866) 518-YARD (9273)

> **···**
>
> On Apr 2, 2007, at 9:37 AM, Ryan Leavengood wrote:
> 
> > On 4/2/07, Matthieu Stone \<matt.stone@cityticketexchange.com\> wrote:
> > 
> > > Ah.. In that case you need to start you long running routine outside of  
> > > rails. Something like backgroundrb, [http://backgroundrb.rubyforge.org/](http://backgroundrb.rubyforge.org/)
> > 
> > This is what we do in the Rails app I'm working on. We call a long  
> > running series of SOAP API calls from BackgrounDRb and then a periodic  
> > executor on the page calls a "progress" function which queries the  
> > BackgrounDrb worker to get the current progress. This works pretty  
> > well.
> > 
> > Though I was very annoyed to see the latest version of BackgrounDrb is  
> > not supported on Windows. We deploy on Linux but develop on Windows so  
> > we are stuck on the last release. If you are listening Ezra, it would  
> > be nice if you could fix this 🙂
> > 
> > Ryan
