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.
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") %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With