Schmooze ::使用grover gem转换html2pdf时处理失败+ [英] Schmooze:: Process failed + when using grover gem to convert html2pdf

查看:127
本文介绍了Schmooze ::使用grover gem转换html2pdf时处理失败+的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

respond_to do |format|
        format.html
        format.pdf do
          grover = Grover.new('http://localhost:3000/generate_report', format: 'A4')
          pdf = grover.to_pdf
          File.open(Rails.root.join('report.pdf'),'wb', encoding: 'ascii-8bit') { |f| f.write(pdf)}

        end
      end

我需要将html页面转换为pdf.但是我收到"schmooze进程失败"的提示,并且在执行grover.to_pdf时系统挂起.它可以在终端上正常运行,但不能在我的rails项目中使用.

I need to convert my html page to pdf. But i get a "schmooze process fail" and the system hangs when it does grover.to_pdf. It works well on terminal but not in my rails project.

推荐答案

听起来您的系统正在挂起,因为默认情况下,当您在开发模式下运行Rails时,您仅使用1个线程运行.

It sounds like your system is hanging because when you run Rails in development mode by default, you are only running with 1 thread.

当您位于请求中并尝试点击generate_report端点时,您正在排队该请求并等待其响应,但是由于Rails一次只能处理一个请求,因此响应永远不会到来,因此该请求永远不会完成,从而导致死锁.

When you are inside of your request, and attempt to hit the generate_report endpoint, you are queuing the request and waiting for it's response, however because Rails can only serve one request at a time, the response never comes, so the request never finishes, causing a deadlock.

通过填充模板或调用ActionController.render()并尝试使用它来尝试在不发出Web请求的情况下获取报告的HTML.

Try to get the HTML for the report without making a web request, by populating a template or calling ActionController.render() and using that instead.

如果这不是您的选择,请将您的Rails服务器配置为在开发模式下使用多个线程(我建议您在开发模式下使用Puma或任何生产用途).

If that's not an option for you, configure your Rails server to use multiple threads in development mode (I recommend you use Puma in dev mode, or whatever production uses).

这篇关于Schmooze ::使用grover gem转换html2pdf时处理失败+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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