views:

128

answers:

2

I have some PDF files in a public rails folder. I want to set the response header "content-disposition" to "attachment". I know I can create a controller to read the files and set the header myself, but is there some general application wide setting that i can enable/configure?

Thanks in advance.

-JP

+2  A: 

Rails/Rack never sees requests to your public folder, your front end web server should handle these. Assuming you are using Apache you could use this approach.

Failing that you can move the files out of the way and use either a rack middleware or a controller as mentioned to handle the request.

cwninja
+2  A: 

What cwninja said.

Assuming Apache as your front-end server:

<FilesMatch "\.(?i:pdf)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

application/octet-stream because application/pdf doesn't force a download in IE sometimes.

Bob Aman