Where have Ruby/Tk examples gone?

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

    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

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.

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:

   (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/

···

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)

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.

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.

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:

   (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/

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.

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
  session[:message] = "starting io..."
  # ...
  if (blah)
    session[:message] = "finished"
  else
    session[:message] = "an error occurred!"
  end
  respond_to do |format|
    format.js { render :update do |page|
      page.insert_html :bottom, 'poll_message', :partial => 'message'
    end
  }
  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,
  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.
>
>

Ah.. In that case you need to start you long running routine outside of
rails. Something like backgroundrb, 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
  session[:message] = "starting io..."
  # ...
  if (blah)
    session[:message] = "finished"
  else
    session[:message] = "an error occurred!"
  end
  respond_to do |format|
    format.js { render :update do |page|
      page.insert_html :bottom, 'poll_message', :partial => 'message'
    end
  }
  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,
  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.
>
>

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 :slight_smile:

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/

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
  session[:message] = "starting io..."
  # ...
  if (blah)
    session[:message] = "finished"
  else
    session[:message] = "an error occurred!"
  end
  respond_to do |format|
    format.js { render :update do |page|
      page.insert_html :bottom, 'poll_message', :partial => 'message'
    end
  }
  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,
  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/

My free Ruby e-book:
http://www.humblelittlerubybook.com/book/

My blogs:

http://www.rubyinpractice.com/

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">
  <% form_remote_tag(:url => {:action => :create_project, :id => @project},
                     :loading => "Element.show('loader');
                                  Element.hide('project_name')",
                     :failure => "Element.show('failure')") do %>
    <p>
      <label for="project_p_name">Project Name:&nbsp;</label>
      <%= text_field 'project', 'p_name' %>
      <%= submit_tag "create" %>
    </p>
  <% 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/

-----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
  session[:message] = "starting io..."
  # ...
  if (blah)
    session[:message] = "finished"
  else
    session[:message] = "an error occurred!"
  end
  respond_to do |format|
    format.js { render :update do |page|
      page.insert_html :bottom, 'poll_message', :partial => 'message'
    end
  }
  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,
  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.
> >
> >
>
>

Ryan-

  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.

  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 :confused:

  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/

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 :slight_smile:

Ryan