PDFkit Rails3.1和开发环境

发布于 2024-12-09 07:40:41 字数 1172 浏览 6 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

忆梦 2024-12-16 07:40:41

这是我正在使用的设置:

  1. 我使用rails server -p 3001 -e test运行rails服务器的第二个实例,它将处理我的PDF资源。服务器将在资产请求传入时打印它们,以便我可以检查一切是否按预期运行。

  2. 我在我的 config/environments/development 文件中使用以下 asset_host

    config.action_controller.asset_host = ->(source, request = nil){
      “http://localhost:3001”如果请求&& request.env['REQUEST_PATH'].include?(".pdf")
    }
    

Here is the setup I am using:

  1. 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.

  2. I use the following asset_host in my config/environments/development file:

    config.action_controller.asset_host = ->(source, request = nil){
      "http://localhost:3001" if request && request.env['REQUEST_PATH'].include?(".pdf")
    }
    
诗笺 2024-12-16 07:40:41

如果您使用 Pow,则可以使用多个工作人员。将其添加到您的 ~/.powconfig

export POW_WORKERS=3

(取自 Pow 手册

If you are using Pow, you can use multiple workers. Add this to your ~/.powconfig

export POW_WORKERS=3

(taken from Pow manual)

你好,陌生人 2024-12-16 07:40:41

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文