Does installing hotwire in a rails project require Javascript?

347 Views Asked by At

My OS is Linux and my distribution is debian-bullseye. My ruby version is 3.1 and my rails version is 7.

I created a rails project

rails new chat --skip-javascript
cd chat/

I installed hotwire

bundle add hotwire-rails
rails hotwire:install

And I got this error

You must either be running with node (package.json) or importmap-rails (config/importmap.rb) to use this gem.

I am trying to follow this tutorial

2

There are 2 best solutions below

0
On BEST ANSWER

it's just a demo, made back when rails 6 was a thing. rails 7 has it by default. rails new chat is all you need. it'll set up all the javascript for you. hotwire-rails is not a thing anymore. Alex

0
On

you only need type this

C:\Users\app>rails importmap:install

press enter then you will see the code below..

Add Importmap include tags in application layout
      insert  app/views/layouts/application.html.erb
Create application.js module as entrypoint
      create  app/javascript/application.js
Use vendor/javascript for downloaded pins
      create  vendor/javascript
      create  vendor/javascript/.keep
Ensure JavaScript files are in the Sprocket manifest
      append  app/assets/config/manifest.js
Configure importmap paths in config/importmap.rb
      create  config/importmap.rb
Copying binstub
      create  bin/importmap

after that type

C:\Users\app>rails hotwire:install

press enter you will see the code below

Create controllers directory
      create  app/javascript/controllers
      create  app/javascript/controllers/index.js
      create  app/javascript/controllers/application.js
      create  app/javascript/controllers/hello_controller.js
Import Stimulus controllers
      append  app/javascript/application.js
Pin Stimulus
Appending: pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true"
      append  config/importmap.rb
Appending: pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
      append  config/importmap.rb
Pin all controllers
Appending: pin_all_from "app/javascript/controllers", under: "controllers"
      append  config/importmap.rb
Import Turbo
      append  app/javascript/application.js
Pin Turbo
      append  config/importmap.rb
Run turbo:install:redis to switch on Redis and use it in development for turbo streams