My rails 7 app is getting an error unknown format for format.js So then what do I need to install, rails-ujs, jquery, ... which npm package or which rails gem I built this site with jsbundling esbuild and cssbundling bootstrap
1 Answer
You should be able to listen to a format.js request with something like this in your controller:
respond_to do |format|
format.js
end
Then you would probably want to have a template with the js.erb template in the views folder.
But be aware that this isn't the preferred way in Rails 7.
Format.js responses was in the Rails-UJS days the way to go.
These days you can use TurboStream for asynchron request.
If you can't use Turbo, you have to install the @rails/ujs npm package and initialize it with:
import Rails from '@rails/ujs';
Rails.start();
1 Comment
bad-reputation
Thanks That works I tried to do it with format.turbo_streams but I couldn't get it to work so I'm using @rails/ujs I'm actually following along with a stripe checkout tutorial written for rails 6 so the contents of create.js.erb are copied and pasted from stripe's docs I don't know what happens when I try to repsond format.turbo_streams