Ruby on Rails 4 javascript not executed

后端 未结 2 2090
醉话见心
醉话见心 2021-02-09 13:11

I have a custom js file in app/assets/javascripts. This is the js file:

//app/assets/javascripts/contacts.js
//$(document).ready(functi         


        
相关标签:
2条回答
  • 2021-02-09 13:39
    $(document).ready(function() { } # Not working with turbo-links
    

    From

    Turbolinks overrides the normal page loading process, the event that this relies on will not be fired. If you have code that looks like this, you must change your code to do this instead:

    $(document).on('ready page:load', function () {
      // you code here
    });
    

    Another question

    0 讨论(0)
  • 2021-02-09 13:39

    With Turbolinks version 5 (starting from Rails 5) you need to use:

    $(document).on("turbolinks:load", function () {
      // YOUR CODE
    });
    
    0 讨论(0)
提交回复
热议问题