DEV Community

Cover image for Rails 7 JS on page load
Jose V
Jose V

Posted on

Rails 7 JS on page load

After diving in many rabbit holes trying to figure out why my JS was not loading after using rails link helper link_to... I think I have the answer.

Rails guide tells us one thing however, this seems to be working for me

document.addEventListener("turbo:load", function () {
  yourFunction();
});
Enter fullscreen mode Exit fullscreen mode

Hope this helps you!

demo: https://rails-7-esbuild.herokuapp.com/
repo: https://github.com/jocvegar/rails_7_esbuild

Top comments (1)

Collapse
 
rtaibah profile image
Rami Taibah

Thank you for this. Helped a lot!