2

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.

Dimitri de Ruiter
  • 725
  • 2
  • 7
  • 26

2 Answers2

2

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?

Community
  • 1
  • 1
Vucko
  • 20,555
  • 10
  • 56
  • 107
0
<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/

Deepak Kumar
  • 101
  • 1
  • 7