0

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 1

0

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();
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.