I have a website and at times I get duplicate records occuring and looking at the logs It's caused by 2 duplicate forms being submitted within 100-200ms of each other. Is there a way to get rails to reject the second form in such a situation?
Asked
Active
Viewed 50 times
2 Answers
2
Additionally to disabling the form with js you can generate a nonce token which only can be used once for the form. Say you create a critical object for a financial transaction you generate a nonce and store this along with the generated object which is backed with a unique constraint.
If the same form is submitted another time an exception is raised due to the violated uniqued constraint which you can then handle accordingly.

jethroo
- 2,086
- 2
- 18
- 30
0
Not really. What you can do is disable the "submit" button once submitted, so that it reduces the possibility that the user will submit it twice.
In Rails you can use the disable_with
setting, that uses jQuery to disable the button after submitted.

Community
- 1
- 1

Simone Carletti
- 173,507
- 49
- 363
- 364