# Please wait dialog

**URL:** <https://www.ruby-forum.com/t/please-wait-dialog/131675>\
**Category:** Rails\
**Created:** [March 12, 2008, 12:45pm UTC](https://www.ruby-forum.com/t/please-wait-dialog/131675 "2008-03-12T12:45:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![makire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@makire](https://www.ruby-forum.com/u/makire)\
**Post date:** [March 12, 2008, 12:45pm UTC](https://www.ruby-forum.com/t/please-wait-dialog/131675/1 "2008-03-12T12:45:59Z")

</div>

Hi everyone

I have an application that needs to execute a shell script with quite  
a long execution time. I would like to show some “Please wait”-dialog  
that can be updated with status from the script. Does anyone have any  
ideas of how to do this in Rails.

Kindest regards

Erik L.

---

<div class="post-metadata">

**Author:** ![makire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@makire](https://www.ruby-forum.com/u/makire)\
**Post date:** [March 12, 2008, 1:15pm UTC](https://www.ruby-forum.com/t/please-wait-dialog/131675/2 "2008-03-12T13:15:15Z")

</div>

Erik L. wrote:

> I have an application that needs to execute a shell script with quite  
> a long execution time. I would like to show some “Please wait”-dialog  
> that can be updated with status from the script. Does anyone have any  
> ideas of how to do this in Rails.

I do something similar in one of my old applications. Mine has a page  
of data, some of which loads quickly and is displayed immediately and  
some which takes longer. For my app, the user clicks a button to select  
which of the longer execution time parts to display, but the principle  
is the same.

The long running task is a remote call to:

def prepare\_get\_details  
render :update do |page|  
page[“info”].update(“

## Preparing details, please wait…
”)  
page \<\< remote\_function(:url =\> {:action =\> :get\_details,  
‘values[days]’ =\>  
params[:values][:days],  
:update =\> ‘info’)  
end  
end

This updates my “info” div with a message (you could display a progress  
bar or something if you like). It then adds javascript to the page to  
call the long running task and set this to replace the contents of the  
same “info” div to replace the “please wait” message. This javascript  
is executed when it is received by the browser.

The initial button is displayed on the main page using:

 \<%= button\_to\_function "Show Details...", remote\_function(:url =\> {:action =\> :prepare\_get\_details, 'values[days]' =\> params[:values][:days]}) %\> 

This allows me to reuse the same calls easily in multiple views. You  
could utilise other options of remote\_function like :loading, etc to do  
it all in one call, but I haven’t played extensively with this.

---

<div class="post-metadata">

**Author:** ![makire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@makire](https://www.ruby-forum.com/u/makire)\
**Post date:** [March 12, 2008, 1:45pm UTC](https://www.ruby-forum.com/t/please-wait-dialog/131675/3 "2008-03-12T13:45:28Z")

</div>

Excellent

I have not used render :update but it seems to be what I am looking  
for. Many, many thanks.

Regards

Erik L.

---

<div class="post-metadata">

**Author:** ![makire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@makire](https://www.ruby-forum.com/u/makire)\
**Post date:** [March 13, 2008, 12:10am UTC](https://www.ruby-forum.com/t/please-wait-dialog/131675/4 "2008-03-13T00:10:49Z")

</div>

Erik L. wrote:

> I have not used render :update but it seems to be what I am looking  
> for. Many, many thanks.

Note also that you can do it all in one go with something like:

 \<%= link\_to\_remote "Show Details...", :update =\> 'info', :url =\> {:action =\> :get\_details}, :before =\> "$('info').update('Please wait...')" %\>

This is simpler than my previous suggestion and more efficient (only 1  
call to the server instead of 2). I originally wrote the 2 step approach  
to avoid including JavaScript directly (I usually prefer to just call  
the Rails helpers - the :before value is JS), but if I was to re-write  
it, I’d probably use this method here and create a helper method to wrap  
it for re-use.
