Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!