I am developing a Rails application that has forms generated using formtastic. I am developing & testing locally - that is - on localhost:3000 w/ Ruby-1.9.2, Rails-3.0.1, jQuery and AJAX.
Below is a sample screen output of the problem I am seeing. My forms are getting submitted twice within 1 second of each other. I can't understand why this is happening. I see this issue w/ all requests - including GET.
Started POST "/businesses/6/edit_balance" for 127.0.0.1 at 2011-01-07 02:31:47 +0530 Processing by BusinessesController#edit_balance as JS Parameters: {"utf8"=>"✓", "authenticity_token"=>"zcWH08sV8kPbAYy7JQX64Cu2e1i/kEB1AB4x5a08CO8="
Started POST "/businesses/6/edit_balance" for 127.0.0.1 at 2011-01-07 02:31:48 +0530 Processing by BusinessesController#edit_balance as JS Parameters: {"utf8"=>"✓", "authenticity_token"=>"zcWH08sV8kPbAYy7JQX64Cu2e1i/kEB1AB4x5a08CO8="
And so I am wondering whether I am making a basic programming error. If yes, then could you please suggest some solutions that I could try.
I had this same problem right after deploying to Heroku... I pre-compiled my assets, and all of a sudden I was getting double AJAX submissions. I guess I somehow ended up with duplicate javascript files in public/assets.
To fix the problem I just deleted my entire public/assets directory.
If you're submitting the form with Javascript, try to set the submit button to be disabled when the form is submitted. With jQuery it would be something like this (not tested):
$('form').submit(function(){
$(this).find(input[type='submit']).attr("disabled", "true");
... // submit form via AJAX
return false;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With