Problem pushing image with rails, turbo frames and turbo streams

87 views Asked by At

I need to (1) upload a file, (2) process the file and generate a variant and (3) return an image to the browser. As the processing takes a few seconds, I want the view to update to show an image to demonstrate that the processing in step (2) has started and then in step (3) update with a new image variant. The refresh for step (3) is being sent via turbo streams via a line in the model

broadcast_replace_later_to("documents")

Steps 1 and 2 work fine. The text in the view updates ok for step (3), but the image is blocked somewhere. If I refresh the page (call it step (4)), the correct image is shown.

I am working in development mode using the default port 3000,rails 7.0.8,turbo-rails 1.5.0, stimulus-rails 1.3.0.

The image files have different urls at each stage. (2) http://localhost:3000/assets/icon.png (3) (failed) http://localhost/rails/active_storage/representations/redirect/random/random/correctname.png (4) http://localhost:3000/rails/active_storage/representations/redirect/random/random/correctname.png

It looks like something is going wrong with the host name. I have tried setting a default_url_options in ApplicationController with {host: 'localhost:3000'} and without the port, but it does not help.

I tried setting config.action_cable.disable_request_forgery_protection = true but the image remains blocked. The Firefox webtools show that the request is blocked.

I tried updating to rails 7.1.1 but get the same results: the image URLs and some link URLs are missing the ":3000" port number.

0

There are 0 answers