【问题标题】:Display PDF's uploaded with paperclip显示使用回形针上传的 PDF
【发布时间】:2016-09-06 10:42:22
【问题描述】:

我使用回形针上传文件(仅限 PDF),现在想在视图中将这些文件显示为 PDF。

这给了我一个空框架<iframe src="<% @document.file %>"></iframe> 这会产生一个图像<%= image_tag @document.file(:large) %>

文件存储在 postgress 中。

【问题讨论】:

  • 也试过了 - 空 iframe

标签: ruby-on-rails paperclip


【解决方案1】:

你有一个语法“问题”:

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

应该是

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

另外,我相信你需要使用它的url,所以我会是这样的:

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

更多信息 - What is the difference between <%, <%=, <%# and -%> in ERB in Rails?

【讨论】:

  • 谢谢;意识到差异但忘记使用它(RoR 新手)。
【解决方案2】:
<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/

【讨论】:

  • 您可以通过解释您在示例代码中所做的工作来改进此答案。
猜你喜欢
  • 1970-01-01
  • 2020-05-17
  • 2015-01-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多