Search code examples
ruby-on-railspaperclip

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.


Solution

  • 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?