How to link to a pdf file with rails?

I have a pdf file in my rails application that I would like to link to. When a user clicks on a link, I want the PDF to be viewed if possible in their browser, and if not, I want it to be downloaded. I'm sure if it's a PDF download link, many browsers will view it by default, but I'm not sure.

+3


source to share


1 answer


If you have a pdf file in your public

application directory , you can create a link like:



<%= link_to "My PDF", asset_path("pdf_file.pdf") %>

      

+5


source







All Articles