Dimitri de Ruiter
Dimitri de Ruiter

Reputation: 745

Display PDF's uploaded with paperclip

I upload files (PDF's only) using paperclip and now want to display these as a PDF in a view.

This gives me an empty frame <iframe src="<% @document.file %>"></iframe> This results in an image <%= image_tag @document.file(:large) %>

the files are stored in postgress.

Upvotes: 2

Views: 1757

Answers (2)

Deepak Kumar
Deepak Kumar

Reputation: 101

<iframe src= <%= @document.url.html_safe %> width="595" height="485" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC; border-width:1px; margin-bottom:5px; max-width: 100%;" allowfullscreen> </iframe>

https://scalified.com/2018/01/16/injecting-pdf-html-page/

Upvotes: 0

Vucko
Vucko

Reputation: 20844

You have an syntax "issue":

<iframe src="<% @document.file %>"></iframe>

Should be

<iframe src="<%= @document.file %>"></iframe>
<!-- notice the equals symbol (=) -->
<!-- which prints something into erb file. -->

Also, I believe you need to use it's url, so I'd be something like this:

<iframe src="<%= @document.file.url(:large) %>"></iframe>

More info - What is the difference between <%, <%=, <%# and -%> in ERB in Rails?

Upvotes: 3

Related Questions