1

I recently upgraded my site from rails 3.1 to rails 7.0.5.1. Now I have lot of legacy javascript code which I want to include via asset pipeline and avoid importmaps. But to use turbo/ turbolinks, I get a message that to use turbo, you should have importmaps or webpacker.

Muhammad Ans
  • 157
  • 8
  • I'm not 100% sure if this is a question ... but to give you a "not answer" you might be better off creating a new directory/repository with a rails 7 install, and then copy in the missing bits from your existing one in order to get rails 7 enabled turbo – Jad Jul 20 '23 at 12:44

1 Answers1

0

You still need to have turbo-rails gem. Skip the turbo:install command, it doesn't do much. Install it yourself:

<%= javascript_include_tag("turbo", type: "module") %>
or
<script type="module" src="https://cdn.jsdelivr.net/npm/@hotwired/turbo-rails@7.3.0/app/assets/javascripts/turbo.min.js"></script>

For module scripts you might need this: https://github.com/guybedford/es-module-shims

You've got Turbo! In addition, if you want to use broadcasts you'll need to set up redis (postgres adapter does work for small ~8kb streams).

Note that you can have importmaps, and esbuild, and some plain files from sprockets all together:

<%= javascript_importmap_tags %>            # importmap-rails
<%= javascript_include_tag("esbuild") %>    # jsbundling-rails
<%= javascript_include_tag("my_old_js") %>  # sprockets

If you get an error about precompilation, add files to manifest.js:
https://stackoverflow.com/a/72367920/207090

Alex
  • 16,409
  • 6
  • 40
  • 56