mardi 29 décembre 2015

Turbolink events don't trigger for pages inside Rails engine

I'm building a platform that gives users a variety of therapeutic tools toward treating anxiety and depression. The 'main app' has some JS with a Turbolink page:change event—everything works swell and the page:change event fires on page changes. For demonstration purposes, this block of code triggers both alerts when navigating throughout 'main app.'

$( document ).ready(function() {
  alert("DOM fully loaded and parsed!");
    $(document).on("page:change", function() {
        alert("Page changed detected!");
    });
});

I have a Rails engine that plugs into the main app. In the engine's JS manifest file, I'm pulling in the main app's JS file like so:

Engine's Application.js:

//= require turbolinks
//= require jquery
//= require jquery_ujs
//= require main_app/custom

The problem is that the Turbolinks on:change event is not triggering when navigating the engine pages (the 'DOM fully loaded...' alert appears as expected). The Chrome debugging console shows no errors, so I'm lead to believe Turbolinks is loaded when viewing engine pages.

tlrd: Turbolinks page:change events works great in the main app, do not fire at all in engine.

Any input is appreciated.

Aucun commentaire:

Enregistrer un commentaire