As you're doing Rails I recommend you check out Stimulus JS (
https://stimulusjs.org/). I've installed it in a recently project (Rails 6, rake webpacker:install:stimulus) and it's like a breath of fresh air. Totally gets out of your way, but lets you add behaviour to your app as you need it.