How to track rails 5 remote link_to to show spinner (I'm using turbolinks 5)

1.2k Views Asked by At

I know there is a lot of question about it, but nothing shows what I want. I want to show a spinner, custom spinner, different from turbolinks default progress bar, I want to show the spinner when a link_to with remote:true is clicked, this click will replace part of the page with a new partial and I want to show the spinner in the time the request is been processing. In my custom.coffe I have:

$(document).on "turbolinks:load", ->
  $('#spinner-container').hide();

  $(document).on "turbolinks:request-start", ->
    $('#spinner-container').show();

  $(document).on "turbolinks:request-end", ->
    $('#spinner-container').hide();

This works with turbolinks with none remote:true links, but when I click the link_to with remote:true nothing happens, I even set sleep(5) in the controller action to see if shows up, the action respond with format.js.

I want something like ajax:start and ajax:success to put in my coffee file, or any other solution. thanks in advance.

1

There are 1 best solutions below

0
On

You need to use turbolinks:click

More info the first point of this list:

https://github.com/turbolinks/turbolinks#full-list-of-events