<div dir="ltr">If this is a rails app, adding a lock_version column to the model gives you this sort of thing for minimal effort.  Saves for a model will fail when the lock version is not correct (see: <a href="http://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html">http://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html</a>).  <div><br></div><div>Although I guess it’s possible there may be race-conditions here?  Can’t say I’ve used it recently to be able to give any hints.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 24 April 2015 at 10:51, Philip stevens <span dir="ltr"><<a href="mailto:phil@retechnica.com" target="_blank">phil@retechnica.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
I agree with Riccardo and I would follow up on this by having the DB, or any persistent layer, store these uniquely. So if one request came close enough to another and the read returned nothing it would still fail on the write.<br>
<br>
I presume when you are talking about special few outpacing the browser you mean they have JavaScript disabled? Otherwise in Rails you can do the following:<br>
<br>
<code><br>
submit_tag 'Submit', data: { disable_with: 'Text’ }<br>
</code><br>
<br>
Regards,<br>
<br>
Phil<br>
<div class="HOEnZb"><div class="h5"><br>
> On 24 Apr 2015, at 09:51, Riccardo Tacconi <<a href="mailto:rtacconi@gmail.com">rtacconi@gmail.com</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> You could put a hash in  a hidden field, when Rails receives the first submission you save it in the session with a timestamp. Every time you receive new submission you check if the has has been already used in the last few seconds, if it was already used you trigger a validation error. You will have to clean stale submission from the session. Otherwise you could put the has in the DB.<br>
><br>
> On 24 April 2015 at 09:43, Andrew Stewart <<a href="mailto:boss@airbladesoftware.com">boss@airbladesoftware.com</a>> wrote:<br>
> Hello LRUG!<br>
><br>
> Some people using my Rails app are speedy double-clickers of form submit buttons.  While I admire their alacrity I would like Rails to ignore the duplicate submissions.<br>
><br>
> Disabling the submit button client-side heads off the quick-but-not-lightning double-clickers.  However a special few still outpace the browser so I am after a server-side solution.<br>
><br>
> I imagine each form submission would have a unique token and the server would ignore or raise an error for submissions with duplicate tokens within a rolling window of, say, a few seconds.  Perhaps this would be handled in a Rack middleware.<br>
><br>
> Does such a thing already exist?  I know this is an old problem but I can't seem to find any decent solutions.<br>
><br>
> Thanks in advance!<br>
><br>
> Yours,<br>
><br>
> Andy Stewart<br>
> _______________________________________________<br>
> Chat mailing list<br>
> <a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
> Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br>
> Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br>
> List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
><br>
><br>
><br>
> --<br>
> Riccardo Tacconi<br>
><br>
> <a href="http://github.com/rtacconi" target="_blank">http://github.com/rtacconi</a><br>
> <a href="http://twitter.com/rtacconi" target="_blank">http://twitter.com/rtacconi</a><br>
> _______________________________________________<br>
> Chat mailing list<br>
> <a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
> Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br>
> Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br>
> List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
<br>
_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br>
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br>
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
</div></div></blockquote></div><br></div>