문제

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)

도움이 되었습니까?

해결책 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.

다른 팁

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top