0

In my Ruby Rails application, there is a Rails pagination. ( = paginate ) , whenever I paginate to other pages, the app reloads, and second page is loaded.

admin/counselors?page=2#all

the above is the href of anchor tags of pagination's next and previous buttons. whenever the page reloads by pagination, the window.load or document.ready methods are not called and all the event handlers attached to various elements is gone. I'm a Javascript developer and new to Rails and no idea whats happening here. Is there any event being fired when this navigation occurs?

River CR Phoenix
  • 311
  • 1
  • 3
  • 14

1 Answers1

1

It's turbolinks (ships with Rails by default) unless you have it disabled. Instead of document.ready() use:

$( document ).on('turbolinks:load', function() {
  console.log("It works on each load!")
}) 

Docs here: https://github.com/turbolinks/turbolinks and duplicate issue here: Rails 5: how to use $(document).ready() with turbo-links

bkunzi01
  • 4,047
  • 1
  • 15
  • 22