Rails 8: Get Started with Hotwire's Turbo Drive
To save myself from looking this up in the future, it's pretty straightforward if you're using importmap-rails
as your javascript handler. Just ensure that importmap-rails
is above turbo-rails
in your Gemfile
.
bin/rails importmap:install
Now we should have some changes after installing Importmap:
# app/javascript/application.js
# Empty file
# app/views/layouts/application.html.erb, at the end of <head>
<%= javascript_importmap_tags %>
# bin/importmap
# a binstub
# config/importmap.rb
# Pin npm packages by running ./bin/importmap
pin "application"
Next, we'll install Turbo:
bin/rails turbo:install
This will make the following changes to enable Turbo:
# app/javascript/application.js
import "@hotwired/turbo-rails"
# config/importmap.rb
pin "@hotwired/turbo-rails", to: "turbo.min.js"
Ruby Forest Druid.