I have implemented a user following mechanism through JavaScript Embedded Ruby which sends requests asynchronously to the server without leaving the page:
$("#follow_form").html("<%= escape_javascript(render('users/unfollow')) %>")
$("#followers").html('<%= @user.followers.count %>')
In the event a user double clicks on the follow button (combined with low server response times), the system sends multiple requests to the server. As a consequence, the current user follows the other user twice and @user.followers.count is increased by +2.
In other words, how can I implement a “Fat finger” control so that my app only sends one request in case the user double clicks several times the follow button?
How can I setup my app in such a way so that, for any button in my app, it gets disabled as soon as it’s clicked and re-enabled based on the AJAX’s result callback?
Looking forward,
Bart
You can disable the button as soon it is clicked and re-enable it from your AJAX’s result callback.