0

Edit: I found the issue to my answer here:

Rails 4: how to use $(document).ready() with turbo-links


As the title says, I have some JQuery at the bottom of the application.js file inside my Rails 5 app. I've noticed it won't fire if I'm traveling from page to page. It will however, work if I just reload the page I'm on.

Just to be perfectly clear, this is my application.js file:

#app/assets/javascripts/application.js
... Rest of file.
//= require_tree .

$( document ).ready(function() {
  alert('test');
});

I won't get an alert at all if I'm just clicking page to page within my app. Again, the alert will only fire if I reload the page I'm currently on.

Any help with this would be wonderful.

Community
  • 1
  • 1
Antonio
  • 691
  • 6
  • 23

2 Answers2

1

As I started to do more research, I found out it was a turbolinks issue.

I was able to reference this answer:

Rails 4: how to use $(document).ready() with turbo-links

changing,

$( document ).ready(function() {...

to

$(document).on('turbolinks:load', function() {...

fixed all my issues.

Community
  • 1
  • 1
Antonio
  • 691
  • 6
  • 23
0

I guess you should try changing $(document).ready() to $(window).load().

Hasan K
  • 540
  • 7
  • 18