2

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 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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..
Storing them in the session is more complicated as you might run into a cookie overflow for adding many cookies to your session.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.