PDFkit Rails3.1和开发环境
我的 Rails 3.1 应用程序使用 PDFkit 来渲染特定页面,并且我遇到了(看起来像是)一个常见问题:尝试生成 pdf 导致进程挂起。 我在 stackoverflow 上找到了这个解决方案:rails 3 和 PDFkit。我在development.rb 文件中添加了一个 config.threadsafe!
条目,这可以工作但是,它要求对于应用程序中任何位置的每次更改,我都必须停止并重新启动我的应用程序。服务器查看我的更改。工作流程中不可接受 - 我目前正在设置 PDF 页面的样式,而且必须执行此操作的过程非常缓慢。
我还发现此处报告了相同的问题: https://github.com/jdpace/PDFKit/issues /110,问题指向此解决方法:http://jguimont.com/post/2627758108/pdfkit-and- it-middleware-on-heroku。
ActionController::Base.asset_host = Proc.new { |source, request|
if request.env["REQUEST_PATH"].include? ".pdf"
"file://#{Rails.root.join('public')}"
else
"#{request.protocol}#{request.host_with_port}"
end
}
这消除了重新启动更改的需要,但是现在当我加载 pdf 时,它没有从资产管道渲染的样式,因为它从公共目录中获取资产。我想如果我知道如何为公共文件夹中的 pdf 模板创建样式表,我可以使用此解决方案。是否有人使用 PDFKit 和 Rails3.1 进行开发,并且所有这些都同步工作?
任何帮助将不胜感激! 谢谢! 托尼
My Rails 3.1 app is using PDFkit to render specific pages, and I'm running into (what seems like) a common problem with where trying to generate the pdf is causing the process to hang.
I found this solution here on stackoverflow: rails 3 and PDFkit. Where I add a config.threadsafe!
entry in my development.rb file and this works BUT it requires that for every change anywhere in the app I have to stop and restart my server to see my changes. NOT acceptable from a workflow - I'm currently setting up the styling for the PDF pages, and it's painfully slow process having to do this.
I also found the same issue reported here: https://github.com/jdpace/PDFKit/issues/110, and the issue points to this workaround: http://jguimont.com/post/2627758108/pdfkit-and-its-middleware-on-heroku.
ActionController::Base.asset_host = Proc.new { |source, request|
if request.env["REQUEST_PATH"].include? ".pdf"
"file://#{Rails.root.join('public')}"
else
"#{request.protocol}#{request.host_with_port}"
end
}
This removes the need to restart the change, BUT now when I load the pdf it's without the styles rendered from the asset pipeline because it's taking the assets from the public directory. I think I could work with this solution if I could know how to create the stylesheets for the pdf templates in the public folder. IS anyone developing with PDFKit and Rails3.1 where this is all working in sync?
Any help would be greatly appreciated!
Thanks!
Tony
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是我正在使用的设置:
我使用
rails server -p 3001 -e test
运行rails服务器的第二个实例,它将处理我的PDF资源。服务器将在资产请求传入时打印它们,以便我可以检查一切是否按预期运行。我在我的
config/environments/development
文件中使用以下asset_host
:Here is the setup I am using:
I run a second instance of rails server with
rails server -p 3001 -e test
which will handle my assets for the PDF. The server will print the assets requests as they come in, so I can check that everything works as expected.I use the following
asset_host
in myconfig/environments/development
file:如果您使用 Pow,则可以使用多个工作人员。将其添加到您的 ~/.powconfig
(取自 Pow 手册)
If you are using Pow, you can use multiple workers. Add this to your ~/.powconfig
(taken from Pow manual)
Rails 3.1 中的 pdfkit 有问题。请参阅我对此相关问题的回答:
pdfkit 不设置 pdf 样式
There's a problem with pdfkit in Rails 3.1. See my answer to this related question:
pdfkit does not style pdfs