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?

Karl Adler
  • 15,780
  • 10
  • 70
  • 88

1 Answers1

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.

Maurício Linhares
  • 39,901
  • 14
  • 121
  • 158
  • 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.. – Karl Adler Nov 30 '11 at 11:57
  • Storing them in the session is more complicated as you might run into a cookie overflow for adding many cookies to your session. – Maurício Linhares Nov 30 '11 at 12:15
  • 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. – Eden Townsend Nov 30 '11 at 14:00