Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

221
Vistas
Uncaught TypeError: $(...).barrating is not a function - Rails / Turbolinks

I'm using Barrating Javascript from https://antennaio.github.io/jquery-bar-rating/ on my Rails application which uses Turbolinks for the page loads.

I've included the barrating.min.js in my javascripts and i'm loading it in my application.js using //=require - it all loads in fine.

I then have a ratings.js located in my assets/javascripts area that makes the call to create the jquery bar on the page.

    document.addEventListener("turbolinks:load", function(event) {
console.log('page is fully loaded');

      //$('#user_track_rating_drums').barrating("destroy");

      $('#user_track_rating_drums').barrating({
        theme: 'bars-horizontal',
        reverse: true,
        initialRating: 1,
         onSelect: function(value, text, event) {
          if (typeof(event) !== 'undefined') {

            if (value >= 8) {
              document.getElementById('average_drums_class').className = 'green';
            }
            else if (value >= 6) { 
              document.getElementById('average_drums_class').className = 'yellow';
            }
             else if (value >= 3) { 
              document.getElementById('average_drums_class').className = 'orange';
            }
            else { 
              document.getElementById('average_drums_class').className = 'red';
            }

            // rating was selected by a user
            console.log(event.target);
          } else {
            // rating was selected programmatically
            // by calling `set` method
          }
        }
      });
})

Everything works fine on the first page load / or if it manually refresh the page, but if it navigate from the page - which uses Turbolinks, when i come back instead of the bars creating again i get a Uncaught TypeError: $(...).barrating is not a function.

I've tried calling the barrating function from the console to attach it to something else on the page but it's not found.

Checked the page and the barrating.min.js is still included in the HEAD.

I tried destroying it before creating it again but no luck. I think its an issue with the page loading with turbolinks

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

So managed to figure it out finally after some trial and error.

I removed the code to call and attach the barrating from the assets/javascripts area and placed it inline directly on the page required.

It now triggers without errors on first and subsequent loads.

Not entirely sure what the problem is with having it in the assets area but this resolves it

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda