I have an submit button and need to ensure that is only pressed/submit one time until the AJAX request is finished. The Javascript solutions are not safe in case of noScript. Is there a propper way to do that in Rails?
1 Answer
Simplest solution would be generating a token and placing it as a hidden form field. When the form is submitted, go to the database and mark the token as used, if another form submit sends the same token again, it's a double submit and you should do whatever you would like to do with it.
3 Comments
Karl Adler
thanks, sounds like a safe and good solution, but i'm not using a local database at my project so I need another solution... maybe session cookies, but that's not such a safe way..
Maurício Linhares
Storing them in the session is more complicated as you might run into a cookie overflow for adding many cookies to your session.
Eden Townsend
Session cookies will only get set on the client if it receives the response. If the user double-clicks the submit button, the browser won't be waiting for a response, therefore will never receive it. Storing a value inside the
session object is probably a much better choice.