PDFkit rails3.1 和开发环境 [英] PDFkit rails3.1 and development env

查看:51
本文介绍了PDFkit rails3.1 和开发环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Rails 3.1 应用程序正在使用 PDFkit 来呈现特定页面,而我遇到了(似乎)一个常见问题,即尝试生成 pdf 导致进程挂起.我在 stackoverflow 上找到了这个解决方案:rails 3 and PDFkit.我在我的 development.rb 文件中添加了一个 config.threadsafe! 条目并且这有效但是它要求对于应用程序中任何地方的每个更改,我必须停止并重新启动我的服务器查看我的更改.工作流程不可接受 - 我目前正在为 PDF 页面设置样式,而且必须执行此操作的过程非常缓慢.

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.

我也发现这里报告了同样的问题:https://github.com/jdpace/PDFKit/issues/110,问题指向此解决方法:http://jguimont.com/post/2627758108/pdfkit-and-its-middleware-on-heroku.

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
}

这消除了重新启动更改的需要,但是现在当我加载 pdf 时,它没有从资产管道呈现的样式,因为它从公共目录中获取资产.如果我知道如何为公共文件夹中的 pdf 模板创建样式表,我想我可以使用这个解决方案.是否有人使用 PDFKit 和 Rails3.1 进行开发,所有这些都可以同步工作?

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

推荐答案

这是我正在使用的设置:

Here is the setup I am using:

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

  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.

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

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")
}

这篇关于PDFkit rails3.1 和开发环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆