Rodrigo Serrano
Rodrigo Serrano

Reputation: 1565

Turbolinks load event never firing in brand new Rails 5.1 app

For some reason Turbolinks is not firing the load event in my app, a brand new, recently created app.

I created a brand new Rails 5.1 app (5.1.4), using rails new (specifically rails new prueba -C -d postgresql --skip-coffee --no-api). This command automatically configures Rails to use Turbolinks, without the need of further manual configuration.

I then created a scaffold for a model (bin/rails g scaffold Thing name), just to have some pages to navigate to.

Finally, I created a file app/assets/javascripts/test.js with the following content:

document.addEventListener("turbolinks.load", function() {
  console.log("Turbolinks loaded")
});

After running the migration, I then run the server in development (bin/rails s), browse (tried both with Chrome v62 and Firefox v57), and check the developer tools console, but instead of seeing the "Turbolinks loaded" message, I get nothing:

According to the Turbolinks README:

[...] the turbolinks:load event, which fires once on the initial page load and again after every Turbolinks visit.

I was therefore expecting to see the message "Turbolinks loaded" in the console every single time.

Any ideas?

Upvotes: 0

Views: 930

Answers (1)

AntonTkachov
AntonTkachov

Reputation: 1784

According to you code you mostly missed event name. You use turbolinks.load, when in fact it's turbolinks:load. Check this url for more details -- https://github.com/turbolinks/turbolinks#running-javascript-when-a-page-loads

Upvotes: 1

Related Questions