Rails has the handy controller method
send_file
Show archive.org snapshot
which lets us download files easily. We can decide whether the file should be downloaded (disposition: 'attachment'
) or shown in the browser (disposition: 'inline'
). The default is disposition: 'attachment'
.
Downloading files will not work when you are calling the controller action from an AJAX request. The browser will try to render the file and insert it in the DOM, which is never what you want.
Unpoly 2
Unpoly (since version 2) can be configured to follow all links (or submit all forms, ...) without having to specify the selector on every link, as described here: https://unpoly.com/up.link.config Show archive.org snapshot .
Make sure to always exclude your download links, otherwise your downloads won't work as expected.
By default will not follow links that have the
standard [download]
attribute
Show archive.org snapshot
. This attribute has the same effect as a Content-Disposition: attachment
header sent by the server.
<a href="..." download>
You can also tell Unpoly to treat that one link as a vanilla Javascript link:
<a href="..." up-follow="false">