简体   繁体   English

使用Rails中的回形针上传后,iFrame中的PDF显示问题

[英]PDF display issue in iFrame once upload using Paperclips in Rails

I am working on Rails application where uploaded PDF using Paperclip Gem . 我正在Rails application上工作,其中使用Paperclip Gem上传了PDF Now try to display PDF using below HTML code. 现在,尝试使用下面的HTML代码display PDF

Upload PDF settings 上载PDF设定

has_attached_file :agreement
validates_attachment_content_type :agreement, :content_type =>["application/pdf"]

<iframe src="/system/contracts/agreements/000/000/022/original/pdf_ag.pdf" align="middle" style="width: 100%; height:720px;" frameborder="0"></iframe>

But got error below 但是下面有错误

error : ActionView::MissingTemplate (Missing template sessions/unknown_route, application/unknown_route

No route matches [GET] "/system/contracts/agreements/000/000/022/original/pdf_ag.pdf"

I tried but same issue again and again. 我尝试了一次又一次的相同问题。 Let me know if any one have idea or trick. 让我知道是否有人有想法或技巧。

Thanks 谢谢

First of all, static content path, for regular Rails app, starts with /public so /public/system/contracts/agreements/ and so on.. 首先,对于常规Rails应用程序,静态内容路径以/public开头,因此/public/system/contracts/agreements/等。

Make sure that your app, in the specific env where you're getting the error, handles static files ( config.serve_static_assets = true for Rails < 5 and config.public_file_server.enabled = true for Rails >= 5). 确保在出现错误的特定环境中,您的应用程序能够处理静态文件(对于Rails <5, config.serve_static_assets = true ;对于Rails> = 5, config.public_file_server.enabled = true )。

Also I'd advise to use absolute path instead of relative. 我也建议使用绝对路径而不是相对路径。 It offers you more flexibility in case you decide to delegate your static files to nginx or CDN server OR you're requesting this PDF from iFrame on the domain different that current app. 如果您决定将静态文件委派给Nginx或CDN服务器,或者在与当前应用程序不同的域中从iFrame请求此PDF,它可以为您提供更大的灵活性。

I store PDF files in public folder and access it. 我将PDF files存储在public folder并进行访问。 It's work for me. 对我来说有用。

Thanks for your supports. 感谢您的支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM