# Message to user while page loads

**URL:** <https://www.ruby-forum.com/t/message-to-user-while-page-loads/124433>\
**Category:** Rails\
**Created:** [December 28, 2007, 5:18pm UTC](https://www.ruby-forum.com/t/message-to-user-while-page-loads/124433 "2007-12-28T17:18:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 28, 2007, 5:18pm UTC](https://www.ruby-forum.com/t/message-to-user-while-page-loads/124433/1 "2007-12-28T17:18:50Z")

</div>

In my RoR project, I have an action that loads a ton of information  
than displays it to the user. When the user ask that resource, he has  
to wait a couple of seconds before something shows up. I’d like to  
give users a message while they are waiting.

I first thought that this would be easy, but I was wrong. How can I  
render a view before processing the action and then render another  
view?

Any help would be greatly appreciated.

Thank you

Olivier D.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 28, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/message-to-user-while-page-loads/124433/2 "2007-12-28T17:35:49Z")

</div>

On Dec 28, 2007, at 10:18 AM, removed\_email\_address@domain.invalid wrote:

> Any help would be greatly appreciated.

In AQDWR v2 (Rails 1.2), there is this example:

\<% form\_remote\_tag(:url =\> {:action =\> ‘iffy\_function’},  
:before =\> “Element.show(‘spinner’);”,  
:success =\> “show\_results(xhr);”,  
:failure =\> “show\_error(xhr);”,  
:complete =\> “Element.hide(‘spinner’);”) do %\>

Maybe this can get you started?

Peace,  
Phillip

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 28, 2007, 5:47pm UTC](https://www.ruby-forum.com/t/message-to-user-while-page-loads/124433/3 "2007-12-28T17:47:33Z")

</div>

I actually thought of using Ajax, since this seems to be the most  
obvious choice. The page would load, then I could send a xhr to the  
server and update a div with my results.

The only problem is, I can’t find a way to call a xhr only once when  
the page is loaded, without the intervention of the user. When I look  
at the prototype library, the periodically\_call\_remote method comes  
closest to what I want. But the only option I have is the frequency  
at which the request should be made. That means the request would be  
made multiple time…

Any idea of an ajax call I could use to do this?

Thanks again

Olivier

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 28, 2007, 6:40pm UTC](https://www.ruby-forum.com/t/message-to-user-while-page-loads/124433/4 "2007-12-28T18:40:55Z")

</div>

On Dec 28, 2007, at 10:46 AM, removed\_email\_address@domain.invalid wrote:

> made multiple time…
> 
> Any idea of an ajax call I could use to do this?

I generally do something like this by outputting some Javascript at  
the end of the page, like

Then in your js file, have some\_function\_call make your xhr request.  
The more appropriate way to do this is to use window.onload, but then  
you’ve got to figure out where to make the assignment

window.onload = some\_function\_call

That’s why I often just put it at the end of the page. There is  
probably a more proper Rails/Prototype way to do it, but I haven’t  
yet dug that deep.

Peace,  
Phillip
