Question

I have a search form on my page, and it is safe for Turbolinks to be enabled as it is using method="get"

Is there any easy way to have the form submit under control of Turbolinks (ie avoid page refresh)

Was it helpful?

Solution 2

At the turbolinks project, there's issue #64 where someone has written a Coffeescript implementation for Rails.

Add the code provided at that link. It adds a turboforms function that needs to be called at page ready, like this:

$(turboforms);

I'm in the process of implementing this, I'll update my answer if I find out anything else that's useful.

OTHER TIPS

You could use something like this in your application.js:

// send get forms through turbolinks
$(document).on("submit", "form[data-turboform]", function(e) {
    Turbolinks.visit(this.action+(this.action.indexOf('?') == -1 ? '?' : '&')+$(this).serialize());
    return false;
});

Then, to enable any form to be sent with turbolinks you would need to add the data-turboform attribute to the form, like this:

<form action="..." method="get" data-turboform>
    ...
</form>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top