Integrate widget using Ruby on Rails with Turbo links

Rodrigo Asai
Rodrigo Asai
  • Updated

To integrate the widget on platforms that use Turbo links using Ruby on Rails, follow the steps below:

  1. In the Ruby on Rails project, open your JavaScript file.
  2. Add the following in the file:

    document.addEventListener('turbolinks:before-visit', () => { document.querySelector("html").removeAttribute("data-uw-w-loader");
              window._userway = false
    }); ['turbolinks:load', 'turbolinks:visit'].forEach((evt) => {
           document.addEventListener(evt, () => {
                 (function(d) {
                     var s = d.createElement("script");
                     s.setAttribute("data-account", "YOUR WIDGET CODE HERE");
                     s.setAttribute("src", "");
                     (d.body || d.head).appendChild(s);

The "data-account" must be updated with your accountID: How to get your widget code, If you're using Turbo and not Turbo links, change from "Turbolinks" to "turbo" on the code.