Snubber
Snubber

Reputation: 1024

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.

Upvotes: 9

Views: 6707

Answers (1)

RAJ
RAJ

Reputation: 9747

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") %>

Upvotes: 11

Related Questions