# Duplicate comments using remote\_form\_for

**URL:** <https://www.ruby-forum.com/t/duplicate-comments-using-remote-form-for/145257>\
**Category:** Rails\
**Created:** [August 7, 2008, 9:06am UTC](https://www.ruby-forum.com/t/duplicate-comments-using-remote-form-for/145257 "2008-08-07T09:06:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chunkyslink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f0a364/32.png) [@chunkyslink](https://www.ruby-forum.com/u/chunkyslink)\
**Post date:** [August 7, 2008, 9:06am UTC](https://www.ruby-forum.com/t/duplicate-comments-using-remote-form-for/145257/1 "2008-08-07T09:06:01Z")

</div>

Is there a best practice way to prevent duplicate comments (or whatever  
the model may be) submissions from a remote\_form\_for? Maybe a time-based  
validation, like the way WordPress seems to prevent comments being  
posted less than 60 seconds apart(?). At the moment, my app allows users  
to double click (or more) on the ‘Submit’ button and, therefore,  
duplicate their comment very easily.

I don’t have a validates uniqueness of on the comment.user\_id and  
comment.body because it wouldn’t be appropriate in this app - we want  
people to be able to post the same comment more than once, at least to a  
certain extent. Is there another way to validate this? Or do I need to  
resort to deactivating/hiding the submit button after a requested is  
made and only showing it again once the comment has been posted?

---

<div class="post-metadata">

**Author:** ![chunkyslink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f0a364/32.png) [@chunkyslink](https://www.ruby-forum.com/u/chunkyslink)\
**Post date:** [August 7, 2008, 9:12am UTC](https://www.ruby-forum.com/t/duplicate-comments-using-remote-form-for/145257/2 "2008-08-07T09:12:22Z")

</div>

You can always make submit button inactive using javascript in :before  
=\> “” block, and then activate it agan (possibly also clearing body of  
comment) in :after =\> '" javascript block.

Also, you can place some indicator, like spinning box to notify user  
that his/her post is being sent.

On Aug 7, 9:06 am, Neil C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![chunkyslink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f0a364/32.png) [@chunkyslink](https://www.ruby-forum.com/u/chunkyslink)\
**Post date:** [August 7, 2008, 9:24am UTC](https://www.ruby-forum.com/t/duplicate-comments-using-remote-form-for/145257/3 "2008-08-07T09:24:59Z")

</div>

Hubert ÅÄ™picki wrote:

> You can always make submit button inactive using javascript in :before  
> =\> “” block, and then activate it agan (possibly also clearing body of  
> comment) in :after =\> '" javascript block.
> 
> Also, you can place some indicator, like spinning box to notify user  
> that his/her post is being sent.
> 
> On Aug 7, 9:06ï¿½am, Neil C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Yes, I have a ‘spinner’ element in the layout. I was considering  
replacing the button with one, but seeing as I prefer to have just one  
place for the spinner (could make for a cleaner user experience and  
development experience!) I do like the sound of the javascript in  
:before =\> “” block. I’ll admit, I’m a little confused by what you mean  
as I haven’t come across the :before, :after (except for before\_create  
filters - presumably not the same thing). Do they go in the comment  
create.js.rjs template or, are they options for the remote\_form\_for  
helper, like the way that :loading and :complete work for indicators?

Finally (sorry for 101 questions) is there any easy way to deactivate a  
submit button, maybe removing the ‘submit’ value?

Thanks.

---

<div class="post-metadata">

**Author:** ![chunkyslink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f0a364/32.png) [@chunkyslink](https://www.ruby-forum.com/u/chunkyslink)\
**Post date:** [August 7, 2008, 7:52pm UTC](https://www.ruby-forum.com/t/duplicate-comments-using-remote-form-for/145257/4 "2008-08-07T19:52:37Z")

</div>

Neil C. wrote:

> Hubert ÅÄ™picki wrote:
> 
> > You can always make submit button inactive using javascript in :before  
> > =\> “” block, and then activate it agan (possibly also clearing body of  
> > comment) in :after =\> '" javascript block.
> > 
> > Also, you can place some indicator, like spinning box to notify user  
> > that his/her post is being sent.
> > 
> > On Aug 7, 9:06ï¿½am, Neil C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> Yes, I have a ‘spinner’ element in the layout. I was considering  
> replacing the button with one, but seeing as I prefer to have just one  
> place for the spinner (could make for a cleaner user experience and  
> development experience!) I do like the sound of the javascript in  
> :before =\> “” block. I’ll admit, I’m a little confused by what you mean  
> as I haven’t come across the :before, :after (except for before\_create  
> filters - presumably not the same thing). Do they go in the comment  
> create.js.rjs template or, are they options for the remote\_form\_for  
> helper, like the way that :loading and :complete work for indicators?
> 
> Finally (sorry for 101 questions) is there any easy way to deactivate a  
> submit button, maybe removing the ‘submit’ value?
> 
> Thanks.

And after a little bit of searching, I came across a very, very easy  
solution to go in the form\_remote\_for options;

:loading =\> “Element.show(‘spinner’);  
$(‘comment\_submit’).disabled=‘disabled’;”,  
:complete =\> “Element.hide(‘spinner’); $(‘comment\_submit’).disabled=‘’;”

I hope that helps someone.
