# Link\_to file

**URL:** <https://www.ruby-forum.com/t/link-to-file/114271>\
**Category:** Rails\
**Created:** [September 10, 2007, 8:32pm UTC](https://www.ruby-forum.com/t/link-to-file/114271 "2007-09-10T20:32:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@sweb](https://www.ruby-forum.com/u/sweb)\
**Post date:** [September 10, 2007, 8:32pm UTC](https://www.ruby-forum.com/t/link-to-file/114271/1 "2007-09-10T20:32:33Z")

</div>

Hi,

This is probably the stupidest question that I’m ever going to ask, but  
how do I create a link to a file? To be more clear, I simply want to  
create a link to a file that I am storing in the /public directory, say  
file.pdf. So, I upload the file to /public/ and then I would like to be  
able to do something like,

link\_to( image\_tag(‘image.jpg’), ‘file.pdf’, {:target =\> “\_blank”})

But, this doesn’t work: It throws a routing error.

I’m sorry, I’m sure this is really easy.

Thanks, S

---

<div class="post-metadata">

**Author:** ![sweb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@sweb](https://www.ruby-forum.com/u/sweb)\
**Post date:** [September 10, 2007, 10:25pm UTC](https://www.ruby-forum.com/t/link-to-file/114271/2 "2007-09-10T22:25:26Z")

</div>

Just use HTML tags 🙂

---

<div class="post-metadata">

**Author:** ![sweb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@sweb](https://www.ruby-forum.com/u/sweb)\
**Post date:** [September 11, 2007, 9:34am UTC](https://www.ruby-forum.com/t/link-to-file/114271/3 "2007-09-11T09:34:45Z")

</div>

You need provide path for file…  
if your file.pdf in /public you should do “/public/file.pdf”,  
otherwise it will look for controller … and throw route error…

This will work

On Sep 10, 9:32 pm, Sam W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![sweb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@sweb](https://www.ruby-forum.com/u/sweb)\
**Post date:** [January 20, 2008, 7:55pm UTC](https://www.ruby-forum.com/t/link-to-file/114271/4 "2008-01-20T19:55:28Z")

</div>

alexey.Creopolis wrote:

> You need provide path for file…  
> if your file.pdf in /public you should do “/public/file.pdf”,  
> otherwise it will look for controller … and throw route error…
> 
> This will work
> 
> On Sep 10, 9:32 pm, Sam W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

I’m having similar problems.

I’m using link\_to which points to a file, however it automatically  
inserts my :Controller into the url which I don’t want.

Can anyone tell me how to stop the controller name from appearing?
