# Problem with Double Submit

**URL:** <https://www.ruby-forum.com/t/problem-with-double-submit/174996>\
**Category:** Rails\
**Created:** [September 5, 2009, 1:33pm UTC](https://www.ruby-forum.com/t/problem-with-double-submit/174996 "2009-09-05T13:33:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hunt\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9e5f3/32.png) [@Hunt\_J](https://www.ruby-forum.com/u/Hunt_J)\
**Post date:** [September 5, 2009, 1:33pm UTC](https://www.ruby-forum.com/t/problem-with-double-submit/174996/1 "2009-09-05T13:33:02Z")

</div>

Hi,

We occasionally have a user pressing “submit” button more than once.  
I know I can disable submit button using “onclick”.

But I sometimes need a more solid solution especially  
for a form that could change a record inside the database.

What could be the best way to solve the problem?  
I need to access to the existing database record first and  
compare the record with a new coming record.

I am now thinking about checking almost all attributes.  
Assuming this is a simple blog, I would check the title  
and post for exact match.

I was trying to find an open source Rails app to have  
a solution, do you know any?

Any help would be appreciated.

Jon

---

<div class="post-metadata">

**Author:** ![Hunt\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9e5f3/32.png) [@Hunt\_J](https://www.ruby-forum.com/u/Hunt_J)\
**Post date:** [September 5, 2009, 6:31pm UTC](https://www.ruby-forum.com/t/problem-with-double-submit/174996/2 "2009-09-05T18:31:05Z")

</div>

If I’m following you correctly, check out the RailsSpace book site.  
You can download the final application. In the application, look at  
the comments conroller in the create action. He’s checking for  
duplicates and throwing them out if so.

> **[Railsspace.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=railsspace.com)**
>
> Get this domain name before someone else does. Quick and painless shopping. Affordable payment options available.

I hope that’s what you meant…

---

<div class="post-metadata">

**Author:** ![Hunt\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9e5f3/32.png) [@Hunt\_J](https://www.ruby-forum.com/u/Hunt_J)\
**Post date:** [September 5, 2009, 7:11pm UTC](https://www.ruby-forum.com/t/problem-with-double-submit/174996/3 "2009-09-05T19:11:29Z")

</div>

On Sep 5, 12:30 pm, Hunt J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> We occasionally have a user pressing “submit” button more than once.  
> I know I can disable submit button using “onclick”.
> 
> But I sometimes need a more solid solution especially  
> for a form that could change a record inside the database.

Optimistic locking etc ?

Fred

---

<div class="post-metadata">

**Author:** ![Hunt\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9e5f3/32.png) [@Hunt\_J](https://www.ruby-forum.com/u/Hunt_J)\
**Post date:** [September 6, 2009, 11:23am UTC](https://www.ruby-forum.com/t/problem-with-double-submit/174996/4 "2009-09-06T11:23:50Z")

</div>

Shoot users that do this - it’s the only way to be sure. 🙂

–Matt J.

On Sep 5, 12:50 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Hunt\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9e5f3/32.png) [@Hunt\_J](https://www.ruby-forum.com/u/Hunt_J)\
**Post date:** [September 7, 2009, 8:33am UTC](https://www.ruby-forum.com/t/problem-with-double-submit/174996/5 "2009-09-07T08:33:19Z")

</div>

If you are updating any state or flag on first submit; you can possibly  
generate an exception if that flag is already set and second submit  
tries to  
set it again. Then you can catch it (rescue) and ignore or display the  
error/message accordingly.

Hope it helps.

## Thanks, Abhinav

à¤…à¤­à¤¿à¤¨à¤µ  
[http://twitter.com/abhinav](http://twitter.com/abhinav)
