Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a link to a pdf file with rails?

I have a pdf file in my rails app that I would like to create a link for. When the user hits the link I want the pdf to be previewed if it is possible in their browser and if not I want it to be downloaded. I'm pretty sure that if it's a download link to a pdf many browsers will preview it by default but I am not sure.

like image 505
Snubber Avatar asked Aug 14 '14 17:08

Snubber


1 Answers

If you have your pdf file in public directory of the application, you can create link like:

<%= link_to "My PDF", asset_path("pdf_file.pdf") %>
like image 200
RAJ Avatar answered Sep 21 '22 06:09

RAJ