Read more

Unpoly 2: Don't try to download files through AJAX requests

Jakob Scholz
September 14, 2021Software engineer at makandra GmbH

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'.

Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot

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">
Posted by Jakob Scholz to makandra dev (2021-09-14 09:29)