def maybe_a_file
if error?
# File doesn't exist - render a turbo-stream to display an error message
return render "error_message"
end
redirect_to "/actual_file.txt"
end
Click the link (when error? returns false)
Expected behaviour
The redirect is followed, and the browser downloads and saves actual_file.txt
Actual behaviour
The redirect is followed, the browser requests actual_file.txt, and the server responds 200 OK with the contents of the file; but the file is not saved by the browser
Cause
Via git bisect, determined to be caused by #968 (thanks to @pythonandchips for digging)
Workaround
Instead of server-side redirecting to the file, return a turbo-stream action to visit the actual file URL in JS (both Turbo.visit and window.location.assign work fine)
Steps to reproduce
Have HTML containing:
Backed by server code:
Click the link (when
error?
returns false)Expected behaviour
The redirect is followed, and the browser downloads and saves
actual_file.txt
Actual behaviour
The redirect is followed, the browser requests
actual_file.txt
, and the server responds 200 OK with the contents of the file; but the file is not saved by the browserCause
Via
git bisect
, determined to be caused by #968 (thanks to @pythonandchips for digging)Workaround
Instead of server-side redirecting to the file, return a turbo-stream action to visit the actual file URL in JS (both
Turbo.visit
andwindow.location.assign
work fine)