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 UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
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)