Search code examples
ruby-on-railsturbolinks

Turbolinks page:fetch not working in Rails


I'm working on an enterprise application which made with Ruby on Rails actually I'm working for the maintenance on the web app, so I want to add a spinner on this application instead of Turbolinks ProgressBar, so on the initial stage I'm testing the page:change & page:receive working but those is not working, look how I tested

$(document).on('page:fetch', function() {
    alert("OK");
});

$(document).on("page:receive", function(){
    alert("OK");
});

also

$(document).on('turbolinks:fetch', function() {
    alert("OK");
});

$(document).on("turbolinks:receive", function(){
    alert("OK");
});

also, browser console is clean no any error.

Thanks


Solution

  • You can see the latest Turbolinks Full List of Events then it should be like this use turbolinks:request-start instead turbolinks:fetch and page:fetch, request-start for receive

    $(function() {
        document.addEventListener('turbolinks:request-start', function() {
            alert("OK");
        });
    
        document.addEventListener("turbolinks:request-end", function(){
            alert("OK");
        });
    });
    

    I have used this for mine and it's working.

    Hope it will help you.