Link_to file

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

Just use HTML tags :slight_smile:

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. [email protected]

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. [email protected]

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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs