The right way to include page-specific JavaScript in Rails

后端 未结 5 767
青春惊慌失措
青春惊慌失措 2021-01-03 06:50

I want to include this, for example:

jQuery(document).ready(function($) {
    $(\'#my-modal\').modal(options)
});

In one specific place in

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-03 07:39

    jquery-readyselector is a plugin that "Extends $().ready() to provide a convenient syntax for page-specific script"

    1. Install jquery-readyselector

    2. Create some CSS classes

      
      
    3. Scope your javascript to your page

      $("#my-modal").ready(function() {
        $('#my-modal').modal(options)
      });
      

    More info in this answer How to load page specific rails 4 js files?

提交回复
热议问题