I am submitting a single text area form via :remote => true. It works great, however if I submit the form twice without reloading the page it renders the partial 3 times. Once on the first submission, then if I enter new text and submit it again it loads the previous partial as well as the current one, resulting in what appears to be 3 submits. It only submits to the database twice, on page refresh one of them dissapears.
My controller looks like so:
respond_to do |format|
format.html { redirect_to(return_to) }
format.js
end
and my this is my js:
$('.comment_form').bind('ajax:success', function(){
$(this).closest('.post').children('.comment_container').prepend("<%= escape_javascript(render :partial => 'public/comment', :object => @comment) %>");
$('.notice').html('<p>New Comment Added</p>');
$(this).children(':input').val('');
$(this).closest('.comment_form_div').slideUp();
return false;
});
I am including jquery and jquery-ujs only once, and I have tried setting $.ajaxSetup({cache:false}); but to no avail.
Has anyone else run into this problem?
just a heads up in case anyone else has this problem.
I had to do: