Forum: Ruby on Rails Preventing Double Submit?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E813e0a366e5d5ddc302fa57a0fc2fab?d=identicon&s=25 Curtis Spencer (Guest)
on 2006-02-24 07:22
(Received via mailing list)
Hi,

I have a sensitive submit button that does a separate credit card
payment post in the controller action, which could take ~2 seconds.  I
want to ensure that if the user double clicks on it, that the controller
won't do two payments.  Right now, I do a redirect after the payment
succeeds, so a refresh of the page won't cause a problem but I am
worried about multiple requests causing multiple payments to go through.

I used to avoid this a few years ago by putting a token into the session
and removing  it on the first request and check to see if it is there at
the top of the controller action.  However, in this case it would just
kick an error to the user saying you tried to double submit the payment,
which is not very elegant.

With Firefox 1.5, I can jam on the submit button many times and it will
only do one request, but do I need to worry about older browsers?  Is
there a rails idiom to take care of this?

Thanks,
Curtis
90bedc2d9234191f2b35dcb9fbbc4390?d=identicon&s=25 Theodore Mills (Guest)
on 2006-02-24 17:57
(Received via mailing list)
In the past I've disabled the submit button with javascript, which is
the easist. But for browsers with javascript disabled, I've also used
the synchronizer token pattern, which entails setting a unique
identifier into the session for any "instance" of a rendered form on a
 page. That way you can check to see if it's been submitted before
re-running processing logic.

Here's an article on the idea, though it's Java:

http://www.javaworld.com/javaworld/javatips/jw-jav...
This topic is locked and can not be replied to.