Rails UJS not firing with Rails 7
To add rails-ujs to Rails 7 you should to do following steps:
- Pin it, to let the application know, which package to use. Enter in bash:
./bin/importmap pin @rails/ujs
And now you have in your config/importmap.rb file something like this:
pin "@rails/ujs", to: "https://ga.jspm.io/npm:@rails/[email protected]/lib/assets/compiled/rails-ujs.js"
- Now include @rails/ujs to your javascript. In file javascript/controllers/application.js add:
import Rails from '@rails/ujs';
Rails.start();
- Restart your application server