Forum: Ruby on Rails Disable double-click with link_to_remote

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
David (Guest)
on 2009-02-23 12:47
(Received via mailing list)
I'm using link_to_remote to load and show a number of partials and am
looking for a way to prevent multiple clicks on the link.  I tried
searching around, but couldn't really find anything.  The way it is
set up now is that if a user double clicks fast enough, two ajax
requests are sent to the server and when both are loaded, things get
messed up.  I'm looking for a good way to eliminate the possibility of
that second ajax request.  Is that possible using link_to_remote?
This is one of my link_to_remotes:

    <%= link_to_remote "Show", :url => {:action => "show"} %>
Frederick C. (Guest)
on 2009-02-23 13:14
(Received via mailing list)
On 23 Feb 2009, at 10:46, David wrote:

>    <%= link_to_remote "Show", :url => {:action => "show"} %>
You could use :before / :onComplete callbacks to disable stuff (either
by setting some js variable or just disabling the link)

Dave L (Guest)
on 2009-02-25 05:28
(Received via mailing list)
Heres what I have and it seems to work:

    $('popup_link_<%= @day %>').observe('click', function()
      if(!making_ajax_request) {
        making_ajax_request = true;
        new Ajax.Request( '/users/serve_popup', { parameters: { day: <
%= @day %>},
           onComplete: function(){ making_ajax_request =
         } );
      } else {    }


Does anyone have any suggestions or see anything wrong?  I am
wondering if it would be better to use onSuccess rather than
onComplete, but maybe not, b/c then if an ajax.request was
unsuccessful the making_ajax_request would be left as true and the
user would be unable to make another ajax request.

On Feb 23, 3:12 am, Frederick C. <removed_email_address@domain.invalid>
Edward Cruz (Guest)
on 2009-02-25 10:00
(Received via mailing list)
I had a similar problem recently, and was able to effectively disable
the link (and prevent multiple clicks) by using the :before directive:


Note: this was only tested in Safari and Firefox...
This topic is locked and can not be replied to.