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?
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...
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.