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

133
Vistas
Rails countdown characters - replace script tag in view

In my Rails 5 app I'm trying to display the amount of characters remaining for the following text area in the view with tag:

<%= form_for @note, :url => registrant_notes_path(@registrant) do |f| %>
  <div>
    <%= f.text_area :body, maxlength: 1000, style: 'width:100%;', id: "review_text" %>

    <%= f.submit "Save", class: "btn btn-primary" %>
  </div>
<% end %>

<script>
$(document).ready(function() {
  var review_text = $("#review_text");
  var counter     = $("#counter");
  var max_length  = counter.data("maximum-length");

  counter.text(max_length - review_text.val().length);
  review_text.keyup(function() {
      counter.text(max_length - $(this).val().length);
  });

});
</script>

How to get rid of this script tag and move it to some js file? I created new file under app/assets/javascripts/notes.js with below code:

$(document).on('turbolinks:load', function() {
  var review_text = $("#review_text");
  var counter     = $("#counter");
  var max_length  = counter.data("maximum-length");

  counter.text(max_length - review_text.val().length);
  review_text.keyup(function() {
      counter.text(max_length - $(this).val().length);
  });

});

but then this JS code stops working - it stops counting down. Should I add this notes.js somewhere or am I missed something else?

about 4 years ago · Juan Pablo Isaza
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