jQuery (document).on not working in production Rails 5





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm currently developing a simple star rating system using jquery on Rails 5. It is working perfectly in development but not production.



However, when I include config.assets.debug = true in /config/production.rb, then it is working. One of the reason that I suspect why it behaves this way is because the precompile application.js somehow had made the jQuery (document).on not working. I had been stucked with this for a few days now, and not be able to find any solution online.



Just wondering, is it possible that there are conflict in the application.js? Is there a need for me to jQuery.noConflict() function?



Appreciate you help on this. Below is all the related code for reference.




application.js




//= require jquery
//= require jquery_ujs
//= require bootstrap/js/bootstrap.bundle
//= require activestorage
//= require Chart.bundle
//= require chartkick
//= require turbolinks
//= require turbolinks-compatibility

// Start for AGENCY
//= require js_agency/jqBootstrapValidation
//= require js_agency/contact_me
//= require js_agency/agency.min
// End for AGENCY

//START FOR ADMIN
//= require jquery_sb-admin/jquery
//= require jquery-easing_sb-admin/jquery.easing
//= require chart.js/Chart.min
//= require datatables/jquery.dataTables
//= require datatables/dataTables.bootstrap4
//= require js_sb-admin/sb-admin.min
//= require js_sb-admin/demo/datatables-demo
//= require js_sb-admin/demo/chart-area-demo
//END FOR ADMIN
//= require_self
//= require_tree .


$(document).on('turbolinks:load',function(){
$('.rating-star').click(function(){
var star = $(this);
var data_form = $(this).attr('data-form');
var data_field = $(this).attr('data-field');
var stars = $(this).attr('data-stars');

for (i=1;i<=5;i++){
if(i <= stars){
$('#' + 'rating' + '_' + data_form + '_' + i).removeClass('glyphicon glyphicon-star-empty');
$('#' + 'rating' + '_' + data_form + '_' + i).addClass('glyphicon glyphicon-star');
} else {
$('#' + 'rating' + '_' + data_form + '_' + i).removeClass('glyphicon glyphicon-star');
$('#' + 'rating' + '_' + data_form + '_' + i).addClass('glyphicon glyphicon-star-empty');
}
}
$('#' + data_field).val(stars);
$('#' + 'feedback').val(stars);
});
});



/views/star/star_rating.html.erb




<div class="col-md-12">
<% data_form = "Taska_try" %>
<% data_field = "taska_rating" %> <!--the field for the stars -->
<% (1..5).each do |i| %>
<h1 id="rating_<%= data_form %>_<%= i %>"
data-form="<%= data_form %>"
data-stars="<%= i %>"
data-field="<%= data_field %>"
class="rating-star glyphicon glyphicon-star-empty">
</h1>
<% end %>
</div>

<div class="col-md-12">
<% data_form = "Classroom_try" %>
<% data_field = "classroom_rating" %> <!--the field for the stars -->
<% (1..5).each do |i| %>
<h1 id="rating_<%= data_form %>_<%= i %>"
data-form="<%= data_form %>"
data-stars="<%= i %>"
data-field="<%= data_field %>"
class="rating-star glyphicon glyphicon-star-empty">
</h1>
<% end %>
</div>









share|improve this question































    0















    I'm currently developing a simple star rating system using jquery on Rails 5. It is working perfectly in development but not production.



    However, when I include config.assets.debug = true in /config/production.rb, then it is working. One of the reason that I suspect why it behaves this way is because the precompile application.js somehow had made the jQuery (document).on not working. I had been stucked with this for a few days now, and not be able to find any solution online.



    Just wondering, is it possible that there are conflict in the application.js? Is there a need for me to jQuery.noConflict() function?



    Appreciate you help on this. Below is all the related code for reference.




    application.js




    //= require jquery
    //= require jquery_ujs
    //= require bootstrap/js/bootstrap.bundle
    //= require activestorage
    //= require Chart.bundle
    //= require chartkick
    //= require turbolinks
    //= require turbolinks-compatibility

    // Start for AGENCY
    //= require js_agency/jqBootstrapValidation
    //= require js_agency/contact_me
    //= require js_agency/agency.min
    // End for AGENCY

    //START FOR ADMIN
    //= require jquery_sb-admin/jquery
    //= require jquery-easing_sb-admin/jquery.easing
    //= require chart.js/Chart.min
    //= require datatables/jquery.dataTables
    //= require datatables/dataTables.bootstrap4
    //= require js_sb-admin/sb-admin.min
    //= require js_sb-admin/demo/datatables-demo
    //= require js_sb-admin/demo/chart-area-demo
    //END FOR ADMIN
    //= require_self
    //= require_tree .


    $(document).on('turbolinks:load',function(){
    $('.rating-star').click(function(){
    var star = $(this);
    var data_form = $(this).attr('data-form');
    var data_field = $(this).attr('data-field');
    var stars = $(this).attr('data-stars');

    for (i=1;i<=5;i++){
    if(i <= stars){
    $('#' + 'rating' + '_' + data_form + '_' + i).removeClass('glyphicon glyphicon-star-empty');
    $('#' + 'rating' + '_' + data_form + '_' + i).addClass('glyphicon glyphicon-star');
    } else {
    $('#' + 'rating' + '_' + data_form + '_' + i).removeClass('glyphicon glyphicon-star');
    $('#' + 'rating' + '_' + data_form + '_' + i).addClass('glyphicon glyphicon-star-empty');
    }
    }
    $('#' + data_field).val(stars);
    $('#' + 'feedback').val(stars);
    });
    });



    /views/star/star_rating.html.erb




    <div class="col-md-12">
    <% data_form = "Taska_try" %>
    <% data_field = "taska_rating" %> <!--the field for the stars -->
    <% (1..5).each do |i| %>
    <h1 id="rating_<%= data_form %>_<%= i %>"
    data-form="<%= data_form %>"
    data-stars="<%= i %>"
    data-field="<%= data_field %>"
    class="rating-star glyphicon glyphicon-star-empty">
    </h1>
    <% end %>
    </div>

    <div class="col-md-12">
    <% data_form = "Classroom_try" %>
    <% data_field = "classroom_rating" %> <!--the field for the stars -->
    <% (1..5).each do |i| %>
    <h1 id="rating_<%= data_form %>_<%= i %>"
    data-form="<%= data_form %>"
    data-stars="<%= i %>"
    data-field="<%= data_field %>"
    class="rating-star glyphicon glyphicon-star-empty">
    </h1>
    <% end %>
    </div>









    share|improve this question



























      0












      0








      0








      I'm currently developing a simple star rating system using jquery on Rails 5. It is working perfectly in development but not production.



      However, when I include config.assets.debug = true in /config/production.rb, then it is working. One of the reason that I suspect why it behaves this way is because the precompile application.js somehow had made the jQuery (document).on not working. I had been stucked with this for a few days now, and not be able to find any solution online.



      Just wondering, is it possible that there are conflict in the application.js? Is there a need for me to jQuery.noConflict() function?



      Appreciate you help on this. Below is all the related code for reference.




      application.js




      //= require jquery
      //= require jquery_ujs
      //= require bootstrap/js/bootstrap.bundle
      //= require activestorage
      //= require Chart.bundle
      //= require chartkick
      //= require turbolinks
      //= require turbolinks-compatibility

      // Start for AGENCY
      //= require js_agency/jqBootstrapValidation
      //= require js_agency/contact_me
      //= require js_agency/agency.min
      // End for AGENCY

      //START FOR ADMIN
      //= require jquery_sb-admin/jquery
      //= require jquery-easing_sb-admin/jquery.easing
      //= require chart.js/Chart.min
      //= require datatables/jquery.dataTables
      //= require datatables/dataTables.bootstrap4
      //= require js_sb-admin/sb-admin.min
      //= require js_sb-admin/demo/datatables-demo
      //= require js_sb-admin/demo/chart-area-demo
      //END FOR ADMIN
      //= require_self
      //= require_tree .


      $(document).on('turbolinks:load',function(){
      $('.rating-star').click(function(){
      var star = $(this);
      var data_form = $(this).attr('data-form');
      var data_field = $(this).attr('data-field');
      var stars = $(this).attr('data-stars');

      for (i=1;i<=5;i++){
      if(i <= stars){
      $('#' + 'rating' + '_' + data_form + '_' + i).removeClass('glyphicon glyphicon-star-empty');
      $('#' + 'rating' + '_' + data_form + '_' + i).addClass('glyphicon glyphicon-star');
      } else {
      $('#' + 'rating' + '_' + data_form + '_' + i).removeClass('glyphicon glyphicon-star');
      $('#' + 'rating' + '_' + data_form + '_' + i).addClass('glyphicon glyphicon-star-empty');
      }
      }
      $('#' + data_field).val(stars);
      $('#' + 'feedback').val(stars);
      });
      });



      /views/star/star_rating.html.erb




      <div class="col-md-12">
      <% data_form = "Taska_try" %>
      <% data_field = "taska_rating" %> <!--the field for the stars -->
      <% (1..5).each do |i| %>
      <h1 id="rating_<%= data_form %>_<%= i %>"
      data-form="<%= data_form %>"
      data-stars="<%= i %>"
      data-field="<%= data_field %>"
      class="rating-star glyphicon glyphicon-star-empty">
      </h1>
      <% end %>
      </div>

      <div class="col-md-12">
      <% data_form = "Classroom_try" %>
      <% data_field = "classroom_rating" %> <!--the field for the stars -->
      <% (1..5).each do |i| %>
      <h1 id="rating_<%= data_form %>_<%= i %>"
      data-form="<%= data_form %>"
      data-stars="<%= i %>"
      data-field="<%= data_field %>"
      class="rating-star glyphicon glyphicon-star-empty">
      </h1>
      <% end %>
      </div>









      share|improve this question
















      I'm currently developing a simple star rating system using jquery on Rails 5. It is working perfectly in development but not production.



      However, when I include config.assets.debug = true in /config/production.rb, then it is working. One of the reason that I suspect why it behaves this way is because the precompile application.js somehow had made the jQuery (document).on not working. I had been stucked with this for a few days now, and not be able to find any solution online.



      Just wondering, is it possible that there are conflict in the application.js? Is there a need for me to jQuery.noConflict() function?



      Appreciate you help on this. Below is all the related code for reference.




      application.js




      //= require jquery
      //= require jquery_ujs
      //= require bootstrap/js/bootstrap.bundle
      //= require activestorage
      //= require Chart.bundle
      //= require chartkick
      //= require turbolinks
      //= require turbolinks-compatibility

      // Start for AGENCY
      //= require js_agency/jqBootstrapValidation
      //= require js_agency/contact_me
      //= require js_agency/agency.min
      // End for AGENCY

      //START FOR ADMIN
      //= require jquery_sb-admin/jquery
      //= require jquery-easing_sb-admin/jquery.easing
      //= require chart.js/Chart.min
      //= require datatables/jquery.dataTables
      //= require datatables/dataTables.bootstrap4
      //= require js_sb-admin/sb-admin.min
      //= require js_sb-admin/demo/datatables-demo
      //= require js_sb-admin/demo/chart-area-demo
      //END FOR ADMIN
      //= require_self
      //= require_tree .


      $(document).on('turbolinks:load',function(){
      $('.rating-star').click(function(){
      var star = $(this);
      var data_form = $(this).attr('data-form');
      var data_field = $(this).attr('data-field');
      var stars = $(this).attr('data-stars');

      for (i=1;i<=5;i++){
      if(i <= stars){
      $('#' + 'rating' + '_' + data_form + '_' + i).removeClass('glyphicon glyphicon-star-empty');
      $('#' + 'rating' + '_' + data_form + '_' + i).addClass('glyphicon glyphicon-star');
      } else {
      $('#' + 'rating' + '_' + data_form + '_' + i).removeClass('glyphicon glyphicon-star');
      $('#' + 'rating' + '_' + data_form + '_' + i).addClass('glyphicon glyphicon-star-empty');
      }
      }
      $('#' + data_field).val(stars);
      $('#' + 'feedback').val(stars);
      });
      });



      /views/star/star_rating.html.erb




      <div class="col-md-12">
      <% data_form = "Taska_try" %>
      <% data_field = "taska_rating" %> <!--the field for the stars -->
      <% (1..5).each do |i| %>
      <h1 id="rating_<%= data_form %>_<%= i %>"
      data-form="<%= data_form %>"
      data-stars="<%= i %>"
      data-field="<%= data_field %>"
      class="rating-star glyphicon glyphicon-star-empty">
      </h1>
      <% end %>
      </div>

      <div class="col-md-12">
      <% data_form = "Classroom_try" %>
      <% data_field = "classroom_rating" %> <!--the field for the stars -->
      <% (1..5).each do |i| %>
      <h1 id="rating_<%= data_form %>_<%= i %>"
      data-form="<%= data_form %>"
      data-stars="<%= i %>"
      data-field="<%= data_field %>"
      class="rating-star glyphicon glyphicon-star-empty">
      </h1>
      <% end %>
      </div>






      javascript jquery html ruby-on-rails ruby






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 17 '18 at 6:40







      Mus KidCare

















      asked Nov 17 '18 at 2:49









      Mus KidCareMus KidCare

      62




      62
























          2 Answers
          2






          active

          oldest

          votes


















          0














          I don't see anywhere you're triggering custom event turbolinks:load. So, I guess you need just:



          $(document).on('load'


          Instead of:



          $(document).on('turbolinks:load'


          Or, if you wish you can trigger the custom event somewhere:



          var turbolinks = jQuery.Event('turbolinks:load');
          $(document).trigger(turbolinks);


          Or simply trigger like:



          $(document).trigger('turbolinks:load');





          share|improve this answer


























          • turbolinks:load event is called on page load: stackoverflow.com/a/36110790/407213

            – Dorian
            Nov 17 '18 at 4:29











          • Hi @Bhojendra Rauniyar, thanks for the feedback. I have tried all you suggestions above, and somehow it doesnt work in development as well. My previous code {$(document).on('turbolinks:load',function(){} work in development, not in production.

            – Mus KidCare
            Nov 17 '18 at 6:26











          • Just wondering, is it possible that there are conflict in the application.js? Is there a need for me to jQuery.noConflict() function?

            – Mus KidCare
            Nov 17 '18 at 6:41











          • In a Rails 5 project with Turbolinks installed $(document).on('load' does not work all the time because of Turbolinks. This only works on when the app is initially loaded. After that Turbolinks takes over and you would be better of using $(document).on('turbolinks:load'.

            – Smek
            Nov 17 '18 at 8:50











          • Correct. I'm currently using turbolinks:load and it works perfectly in development. It stop to work in production.

            – Mus KidCare
            Nov 17 '18 at 8:57



















          -1














          I don´t know the reason but the solution is simple



          Just clone the jquery function before load any script in the project and then use it when you need it.



          $(document).ready(function() {

          myDocOn = $(document).on();

          myDocOn.on("mousemove",
          function() {
          // refeshMyTime();

          }
          )

          )};


          No matter what happen whit the original function in any mdoification by another script, your function will be save.



          This code works for me.



          ¿Why i have a negative point?



          I can't answer anymore just by this =( please help me.






          share|improve this answer


























          • Thanks for the suggestion. I have added this to my application.js, but it still doesnt work.

            – Mus KidCare
            Nov 17 '18 at 6:31











          • mmmm , don´t add this in you application.js file, you must add it in a independent file wich will be loaded between jquery file and any other,, just after your jquery file, because , the function .on is highly probable pure. In some place on another js file , this function is modifided. An close the keys, i have a little mistake paste it that code.

            – Daniel Badillo
            Nov 18 '18 at 9:59














          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53347752%2fjquery-document-on-not-working-in-production-rails-5%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          I don't see anywhere you're triggering custom event turbolinks:load. So, I guess you need just:



          $(document).on('load'


          Instead of:



          $(document).on('turbolinks:load'


          Or, if you wish you can trigger the custom event somewhere:



          var turbolinks = jQuery.Event('turbolinks:load');
          $(document).trigger(turbolinks);


          Or simply trigger like:



          $(document).trigger('turbolinks:load');





          share|improve this answer


























          • turbolinks:load event is called on page load: stackoverflow.com/a/36110790/407213

            – Dorian
            Nov 17 '18 at 4:29











          • Hi @Bhojendra Rauniyar, thanks for the feedback. I have tried all you suggestions above, and somehow it doesnt work in development as well. My previous code {$(document).on('turbolinks:load',function(){} work in development, not in production.

            – Mus KidCare
            Nov 17 '18 at 6:26











          • Just wondering, is it possible that there are conflict in the application.js? Is there a need for me to jQuery.noConflict() function?

            – Mus KidCare
            Nov 17 '18 at 6:41











          • In a Rails 5 project with Turbolinks installed $(document).on('load' does not work all the time because of Turbolinks. This only works on when the app is initially loaded. After that Turbolinks takes over and you would be better of using $(document).on('turbolinks:load'.

            – Smek
            Nov 17 '18 at 8:50











          • Correct. I'm currently using turbolinks:load and it works perfectly in development. It stop to work in production.

            – Mus KidCare
            Nov 17 '18 at 8:57
















          0














          I don't see anywhere you're triggering custom event turbolinks:load. So, I guess you need just:



          $(document).on('load'


          Instead of:



          $(document).on('turbolinks:load'


          Or, if you wish you can trigger the custom event somewhere:



          var turbolinks = jQuery.Event('turbolinks:load');
          $(document).trigger(turbolinks);


          Or simply trigger like:



          $(document).trigger('turbolinks:load');





          share|improve this answer


























          • turbolinks:load event is called on page load: stackoverflow.com/a/36110790/407213

            – Dorian
            Nov 17 '18 at 4:29











          • Hi @Bhojendra Rauniyar, thanks for the feedback. I have tried all you suggestions above, and somehow it doesnt work in development as well. My previous code {$(document).on('turbolinks:load',function(){} work in development, not in production.

            – Mus KidCare
            Nov 17 '18 at 6:26











          • Just wondering, is it possible that there are conflict in the application.js? Is there a need for me to jQuery.noConflict() function?

            – Mus KidCare
            Nov 17 '18 at 6:41











          • In a Rails 5 project with Turbolinks installed $(document).on('load' does not work all the time because of Turbolinks. This only works on when the app is initially loaded. After that Turbolinks takes over and you would be better of using $(document).on('turbolinks:load'.

            – Smek
            Nov 17 '18 at 8:50











          • Correct. I'm currently using turbolinks:load and it works perfectly in development. It stop to work in production.

            – Mus KidCare
            Nov 17 '18 at 8:57














          0












          0








          0







          I don't see anywhere you're triggering custom event turbolinks:load. So, I guess you need just:



          $(document).on('load'


          Instead of:



          $(document).on('turbolinks:load'


          Or, if you wish you can trigger the custom event somewhere:



          var turbolinks = jQuery.Event('turbolinks:load');
          $(document).trigger(turbolinks);


          Or simply trigger like:



          $(document).trigger('turbolinks:load');





          share|improve this answer















          I don't see anywhere you're triggering custom event turbolinks:load. So, I guess you need just:



          $(document).on('load'


          Instead of:



          $(document).on('turbolinks:load'


          Or, if you wish you can trigger the custom event somewhere:



          var turbolinks = jQuery.Event('turbolinks:load');
          $(document).trigger(turbolinks);


          Or simply trigger like:



          $(document).trigger('turbolinks:load');






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 17 '18 at 3:00


























          community wiki





          2 revs
          Bhojendra Rauniyar














          • turbolinks:load event is called on page load: stackoverflow.com/a/36110790/407213

            – Dorian
            Nov 17 '18 at 4:29











          • Hi @Bhojendra Rauniyar, thanks for the feedback. I have tried all you suggestions above, and somehow it doesnt work in development as well. My previous code {$(document).on('turbolinks:load',function(){} work in development, not in production.

            – Mus KidCare
            Nov 17 '18 at 6:26











          • Just wondering, is it possible that there are conflict in the application.js? Is there a need for me to jQuery.noConflict() function?

            – Mus KidCare
            Nov 17 '18 at 6:41











          • In a Rails 5 project with Turbolinks installed $(document).on('load' does not work all the time because of Turbolinks. This only works on when the app is initially loaded. After that Turbolinks takes over and you would be better of using $(document).on('turbolinks:load'.

            – Smek
            Nov 17 '18 at 8:50











          • Correct. I'm currently using turbolinks:load and it works perfectly in development. It stop to work in production.

            – Mus KidCare
            Nov 17 '18 at 8:57



















          • turbolinks:load event is called on page load: stackoverflow.com/a/36110790/407213

            – Dorian
            Nov 17 '18 at 4:29











          • Hi @Bhojendra Rauniyar, thanks for the feedback. I have tried all you suggestions above, and somehow it doesnt work in development as well. My previous code {$(document).on('turbolinks:load',function(){} work in development, not in production.

            – Mus KidCare
            Nov 17 '18 at 6:26











          • Just wondering, is it possible that there are conflict in the application.js? Is there a need for me to jQuery.noConflict() function?

            – Mus KidCare
            Nov 17 '18 at 6:41











          • In a Rails 5 project with Turbolinks installed $(document).on('load' does not work all the time because of Turbolinks. This only works on when the app is initially loaded. After that Turbolinks takes over and you would be better of using $(document).on('turbolinks:load'.

            – Smek
            Nov 17 '18 at 8:50











          • Correct. I'm currently using turbolinks:load and it works perfectly in development. It stop to work in production.

            – Mus KidCare
            Nov 17 '18 at 8:57

















          turbolinks:load event is called on page load: stackoverflow.com/a/36110790/407213

          – Dorian
          Nov 17 '18 at 4:29





          turbolinks:load event is called on page load: stackoverflow.com/a/36110790/407213

          – Dorian
          Nov 17 '18 at 4:29













          Hi @Bhojendra Rauniyar, thanks for the feedback. I have tried all you suggestions above, and somehow it doesnt work in development as well. My previous code {$(document).on('turbolinks:load',function(){} work in development, not in production.

          – Mus KidCare
          Nov 17 '18 at 6:26





          Hi @Bhojendra Rauniyar, thanks for the feedback. I have tried all you suggestions above, and somehow it doesnt work in development as well. My previous code {$(document).on('turbolinks:load',function(){} work in development, not in production.

          – Mus KidCare
          Nov 17 '18 at 6:26













          Just wondering, is it possible that there are conflict in the application.js? Is there a need for me to jQuery.noConflict() function?

          – Mus KidCare
          Nov 17 '18 at 6:41





          Just wondering, is it possible that there are conflict in the application.js? Is there a need for me to jQuery.noConflict() function?

          – Mus KidCare
          Nov 17 '18 at 6:41













          In a Rails 5 project with Turbolinks installed $(document).on('load' does not work all the time because of Turbolinks. This only works on when the app is initially loaded. After that Turbolinks takes over and you would be better of using $(document).on('turbolinks:load'.

          – Smek
          Nov 17 '18 at 8:50





          In a Rails 5 project with Turbolinks installed $(document).on('load' does not work all the time because of Turbolinks. This only works on when the app is initially loaded. After that Turbolinks takes over and you would be better of using $(document).on('turbolinks:load'.

          – Smek
          Nov 17 '18 at 8:50













          Correct. I'm currently using turbolinks:load and it works perfectly in development. It stop to work in production.

          – Mus KidCare
          Nov 17 '18 at 8:57





          Correct. I'm currently using turbolinks:load and it works perfectly in development. It stop to work in production.

          – Mus KidCare
          Nov 17 '18 at 8:57













          -1














          I don´t know the reason but the solution is simple



          Just clone the jquery function before load any script in the project and then use it when you need it.



          $(document).ready(function() {

          myDocOn = $(document).on();

          myDocOn.on("mousemove",
          function() {
          // refeshMyTime();

          }
          )

          )};


          No matter what happen whit the original function in any mdoification by another script, your function will be save.



          This code works for me.



          ¿Why i have a negative point?



          I can't answer anymore just by this =( please help me.






          share|improve this answer


























          • Thanks for the suggestion. I have added this to my application.js, but it still doesnt work.

            – Mus KidCare
            Nov 17 '18 at 6:31











          • mmmm , don´t add this in you application.js file, you must add it in a independent file wich will be loaded between jquery file and any other,, just after your jquery file, because , the function .on is highly probable pure. In some place on another js file , this function is modifided. An close the keys, i have a little mistake paste it that code.

            – Daniel Badillo
            Nov 18 '18 at 9:59


















          -1














          I don´t know the reason but the solution is simple



          Just clone the jquery function before load any script in the project and then use it when you need it.



          $(document).ready(function() {

          myDocOn = $(document).on();

          myDocOn.on("mousemove",
          function() {
          // refeshMyTime();

          }
          )

          )};


          No matter what happen whit the original function in any mdoification by another script, your function will be save.



          This code works for me.



          ¿Why i have a negative point?



          I can't answer anymore just by this =( please help me.






          share|improve this answer


























          • Thanks for the suggestion. I have added this to my application.js, but it still doesnt work.

            – Mus KidCare
            Nov 17 '18 at 6:31











          • mmmm , don´t add this in you application.js file, you must add it in a independent file wich will be loaded between jquery file and any other,, just after your jquery file, because , the function .on is highly probable pure. In some place on another js file , this function is modifided. An close the keys, i have a little mistake paste it that code.

            – Daniel Badillo
            Nov 18 '18 at 9:59
















          -1












          -1








          -1







          I don´t know the reason but the solution is simple



          Just clone the jquery function before load any script in the project and then use it when you need it.



          $(document).ready(function() {

          myDocOn = $(document).on();

          myDocOn.on("mousemove",
          function() {
          // refeshMyTime();

          }
          )

          )};


          No matter what happen whit the original function in any mdoification by another script, your function will be save.



          This code works for me.



          ¿Why i have a negative point?



          I can't answer anymore just by this =( please help me.






          share|improve this answer















          I don´t know the reason but the solution is simple



          Just clone the jquery function before load any script in the project and then use it when you need it.



          $(document).ready(function() {

          myDocOn = $(document).on();

          myDocOn.on("mousemove",
          function() {
          // refeshMyTime();

          }
          )

          )};


          No matter what happen whit the original function in any mdoification by another script, your function will be save.



          This code works for me.



          ¿Why i have a negative point?



          I can't answer anymore just by this =( please help me.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 29 '18 at 1:32

























          answered Nov 17 '18 at 3:07









          Daniel BadilloDaniel Badillo

          112




          112













          • Thanks for the suggestion. I have added this to my application.js, but it still doesnt work.

            – Mus KidCare
            Nov 17 '18 at 6:31











          • mmmm , don´t add this in you application.js file, you must add it in a independent file wich will be loaded between jquery file and any other,, just after your jquery file, because , the function .on is highly probable pure. In some place on another js file , this function is modifided. An close the keys, i have a little mistake paste it that code.

            – Daniel Badillo
            Nov 18 '18 at 9:59





















          • Thanks for the suggestion. I have added this to my application.js, but it still doesnt work.

            – Mus KidCare
            Nov 17 '18 at 6:31











          • mmmm , don´t add this in you application.js file, you must add it in a independent file wich will be loaded between jquery file and any other,, just after your jquery file, because , the function .on is highly probable pure. In some place on another js file , this function is modifided. An close the keys, i have a little mistake paste it that code.

            – Daniel Badillo
            Nov 18 '18 at 9:59



















          Thanks for the suggestion. I have added this to my application.js, but it still doesnt work.

          – Mus KidCare
          Nov 17 '18 at 6:31





          Thanks for the suggestion. I have added this to my application.js, but it still doesnt work.

          – Mus KidCare
          Nov 17 '18 at 6:31













          mmmm , don´t add this in you application.js file, you must add it in a independent file wich will be loaded between jquery file and any other,, just after your jquery file, because , the function .on is highly probable pure. In some place on another js file , this function is modifided. An close the keys, i have a little mistake paste it that code.

          – Daniel Badillo
          Nov 18 '18 at 9:59







          mmmm , don´t add this in you application.js file, you must add it in a independent file wich will be loaded between jquery file and any other,, just after your jquery file, because , the function .on is highly probable pure. In some place on another js file , this function is modifided. An close the keys, i have a little mistake paste it that code.

          – Daniel Badillo
          Nov 18 '18 at 9:59




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53347752%2fjquery-document-on-not-working-in-production-rails-5%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine