# How to support file downloads (e.g., PDFs, .docs)

**URL:** <https://www.ruby-forum.com/t/how-to-support-file-downloads-e-g-pdfs-docs/127086>\
**Category:** Rails\
**Created:** [January 24, 2008, 9:10pm UTC](https://www.ruby-forum.com/t/how-to-support-file-downloads-e-g-pdfs-docs/127086 "2008-01-24T21:10:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sd.codewarrior](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@sd.codewarrior](https://www.ruby-forum.com/u/sd.codewarrior)\
**Post date:** [January 24, 2008, 9:10pm UTC](https://www.ruby-forum.com/t/how-to-support-file-downloads-e-g-pdfs-docs/127086/1 "2008-01-24T21:10:05Z")

</div>

I have a simple website in which I upload files (e.g., PDFs  
and .docs) for later download by visitors to the site. I store the  
files under public/images in a sub-directory corresponding to the  
particular file. An example location might be

public/images/books/#{toc\_dir}/#{toc\_name}

where toc\_dir = “Book\_TOC/toc” and toc\_name = “book.pdf”

In my index.rhtml file I use the following code to create a link to  
the above resource:

\<% if book.toc\_file\_name != nil %\>  
\<% toc\_name = book.toc\_file\_name %\>  
\<% toc\_dir = “#{book.title.gsub(/[^a-zA-Z0-9.]/, ‘\_’)}/toc” %\>  
\<%= link\_to(“TOC”, “/images/books/#{toc\_dir}/#{toc\_name}”, :popup =\>  
true) -%\>  
\<% end %\>

In my test environment (Windows XP, InstantRails) this is works just  
fine but when I upload to the production environment (Linux/CentOS)  
clicking the link results in the following complaint:

no route found to match “/images/books/Book\_TOX/excerpt/book.pdf” with  
{:method=\>:get}

What is the proper way to deliver files. I tried send\_file but  
couldn’t get that working. I also tried an absolute path in the  
link\_to command but that resulted in the same route complaint. Is it  
necessary to put the files in a directory that is not under public/  
images?

Any help is appreciated.

- SD

---

<div class="post-metadata">

**Author:** ![sd.codewarrior](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@sd.codewarrior](https://www.ruby-forum.com/u/sd.codewarrior)\
**Post date:** [January 24, 2008, 9:29pm UTC](https://www.ruby-forum.com/t/how-to-support-file-downloads-e-g-pdfs-docs/127086/2 "2008-01-24T21:29:51Z")

</div>

most likely you are linking to a non-existent file.

The fcgi/mongrel process shouldn’t even be picking up the request.  
Either the file doesn’t exist (at that location) or you have massively  
mis configured your server

---

<div class="post-metadata">

**Author:** ![sd.codewarrior](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@sd.codewarrior](https://www.ruby-forum.com/u/sd.codewarrior)\
**Post date:** [January 24, 2008, 9:30pm UTC](https://www.ruby-forum.com/t/how-to-support-file-downloads-e-g-pdfs-docs/127086/3 "2008-01-24T21:30:49Z")

</div>

you should consider using file\_column plugin
