Suppose I have a Rails controller method, which is executed when the user submits a form. Now, the user submits the form, and while the method is running (and hasn’t rendered the next page to the user), the user hits “Refresh”. What is going to happen? Will the method stop running and restart, or will there be another thread to run the method once more?
Suppose I have a Rails controller method, which is executed when the user submits
Share
I had to find the answer out for this myself, here is what I found (using Network tab on chrome inspector)
The browser sends the following requests:
The users hits refresh, which causes:
In other words, it doesn’t re-submit the form, it re-brings up the edit form.
Now… if instead of hitting refresh they hit submit a second time, that will send a second
which will call your controller method a second time.
If that is a problem, you may need to add some logic to ignore or otherwise handle subsequent submits (simple state machine?). Remember the days when e-commerce sites had a message like “Do not hit submit twice” after you bought something… they didn’t have that logic 🙂