Javascript "please wait" image

When I used to write Perl CGI scripts I displayed an animated gif image
whilst waiting for a long database query to load, and some javascript to
remove the image once the content was available.
I’d like to do the same thing with Rails, but it’s not clear to me how
to do this in Rails. Does anyone have any suggestions?

Milo T. wrote:

When I used to write Perl CGI scripts I displayed an animated gif image
whilst waiting for a long database query to load, and some javascript to
remove the image once the content was available.
I’d like to do the same thing with Rails, but it’s not clear to me how
to do this in Rails. Does anyone have any suggestions?

in rails-ajax you have a :loading => “Jsfunct()”, :complete =>
“Jsfunct2()” for all of the prototype based js-rails things.

you can do something like (given you have the :defaults js files
included in the )
DOM


The ajax call will replace this div

link_to_remote “load query”,
:url => {:controller=>‘mycontroller’, :action=>‘queryloader’},
:update => “dom_updater”,
:loading => “Element.show(‘spinner’)”,
:complete => “Element.hide(‘spinner’)”

class cController

def queryloader
BigModel.find(:all) # make long query
render_text “this will be replaced in the div called dom_updater!”
end

end


…the img is actually placed on the page at start but with display:none.
when the ajax call is made, the :loading opt loads a js function (it
could be any function u define, i chose the simple prototype
Element.show/hide) that displays / hides the img according to the
process of the action in the background.

hope it helps!
s

Shai R. wrote:

…the img is actually placed on the page at start but with display:none.
when the ajax call is made, the :loading opt loads a js function (it
could be any function u define, i chose the simple prototype
Element.show/hide) that displays / hides the img according to the
process of the action in the background.

That looks a lot better than my crude Perl methods! I will give it a go,
but I’m not sure whether it will work with my odd setup (can’t test
right now, whilst I populate the database).
The search button submits a form, calling the search method. If there is
anything found by the search then it stores the results in the session
and re-directs to a “view results” page. So, the “search” page is never
actually rendered.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs