File download using Paperclip

seadowg picture seadowg · Feb 16, 2011 · Viewed 13.6k times · Source

I am using Rails to make a small file upload app. For file attachment I am using the wonderful Paperclip but I can't work out how to do downloads.

How would I create a link in my show view, that is passed the file id, for instance that would allow the user to download a file on my server?

Answer

Syed Aslam picture Syed Aslam · Feb 16, 2011

If the file uploaded is attached to a model, e.g. as an attribute called avatar, then you can create a link like:

<%= link_to "Download", model.avatar.url(:original, false) %>

Replace avatar with the name of your attribute.