rails/turbolinks — pull request #85 by reednj77 (2012-10-10 09:07:58+00:00)
Title: Disable for page after failed form submission - Fix #79

This is a proposed fix for issue #79. It's a fair amount of code for such a rare case, but as far as I can tell, it gets rid of the issue.

When a form is submitted, the form's action is saved in a HTML5 `sessionStorage` key so it can be read (and removed) on the resulting page load. Turbolinks will then be initialized like normal unless these two conditions are true:

1. The server did not redirect to a URL different from the form's action, indicating a possible failed submission.
* *if the submitted form's action matches the new document.location.href*
2. The new page contains a form with the same action as the form that was just submitted, meaning the form was most likely rerendered with errors.

If both of these conditions are true, I chose to have it just skip the creation of the `click` and `popstate` event handlers rather than adding a `data-no-turbolink` attribute to the body.