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.
On Dec 28, 2007, at 10:18 AM, [email protected] 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
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
On Dec 28, 2007, at 10:46 AM, [email protected] 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