rails/turbolinks — pull request #379 by Thibaut (2014-05-19 19:17:13+00:00)
Title: [WIP] Add form/POST support

At Shopify we've extended Turbolinks to support partial DOM replacement in order to submit all our forms and links via AJAX and — instead of using server-generated JavaScript responses — update portions of the page without losing focus and other DOM state.

Our current implementation uses jQuery to submit forms and only passes the successful `xhr` object back to Turbolinks to refresh the page. Ideally this should be fully automatic in Rails/Turbolinks but this requires adding POST/form support to Turbolinks. I'm not entirely sure this is the best approach since it brings "hard to maintain" code to Turbolinks, but we wanted to give it a shot and open up the discussion (before extracting partial page replacement from Shopify).

The main challenges are form serialization, which is harder to do and maybe less reliable with plain JavaScript than `jQuery.fn.serialize`, and what to do when the server responds with a response that Turbolinks can't handle (e.g. 500). In that case I don't think Turbolinks should re-submit the form without AJAX as it does with links (maybe we could simply fire an event?).

Note that this code is just a proof of concept / untested. If we decide to go with this approach I'd be happy to write a full test suite / get it ready for production.

Another option might be to tie this in `jquery-ujs`.

@dhh @josh @arthurnn @jduff what do you think?