在生产中错误“未预编译”的js文件试图通过Rails中的wicked_pdf呈现PDF

时间:2013-01-16 13:59:29

标签: ruby-on-rails asset-pipeline wkhtmltopdf production wicked-pdf

我在生产服务器上遇到了wicked_pdf问题。我在_results.pdf.haml中有这样的代码:

#container

= wicked_pdf_javascript_include_tag "pdf_application"
:javascript
  $(document).ready(function(){drawPDFCharts(#{generate_javascript_for_pdf_generator(@poll.answer_count_per_question)}, "container")});

这里是pdf_application.js

//= require jquery
//= require highcharts
//= require poll-pdf-chart-generation.js.coffee

在本地机器和舞台上一直很好,但在制作时有一个错误:

Started GET "/121-consumer-electronics.pdf" for 94.76.74.170 at 2013-01-16 13:52:53 +0000
Processing by PollsController#show as PDF
  Parameters: {"id"=>"121-consumer-electronics"}
***************WICKED***************
  Rendered polls/_results.pdf.haml (145.7ms)
Completed 500 Internal Server Error in 816ms

ActionView::Template::Error (pdf_application.js isn't precompiled):
    8: 
    9: #container
    10: 
    11: = wicked_pdf_javascript_include_tag "pdf_application"
    12: :javascript
    13:   $(document).ready(function(){drawPDFCharts(#{generate_javascript_for_pdf_generator(@poll.answer_count_per_question)}, "container")});

这是我的production.rb:

# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true

# Compress JavaScripts and CSS
config.assets.compress = true

# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false

# Generate digests for assets URLs
config.assets.digest = true

我无法弄清楚如何使它工作,我在这里看到了一些类似的问题,我试图将此文件添加到预编译阵列并重新启动服务器,但它没有帮助。因为我得到了我在本地机器上编译资产,并且没有编译生产,并且当我尝试运行它时,这个文件不会被预编译...

2 个答案:

答案 0 :(得分:0)

听起来.js文件已更改,未重新编译。 Rails 3将js,css和stylesheets编译成一个文件,一次发送到浏览器。如果assets目录中的任何内容发生更改,则必须重新编译整个内容。尝试

bundle exec rake assets:precompile
祝你好运

鲍勃

答案 1 :(得分:0)

哪个文件包含您要使用的javascript代码?是poll-pdf-chart-generation.js.coffee吗?

我不确定邪恶的pdf是否可以使用咖啡文件,但如果我错了,有人可以请你纠正。

我相信解决方案是尝试将poll-pdf-chart-generation.js.coffee转换为js文件并将其添加到production.rb:

config.assets.precompile += ['poll-pdf-chart-generation.js']

参考:Rails guide on asset pipeline

更改wickedpdf include标记以查看预编译的js资产:

wicked_pdf_javascript_include_tag "poll-pdf-chart-generation"

您还需要预编译资产:

bundle exec rake assets:precompile