在 wicked_pdf 中渲染 jQuery
我在我的应用程序中使用 Highcharts 来渲染图表。一切工作正常,除了当我想将包含图表的页面转换为 PDF 时。我正在使用 wicked_pdf。这是我的控制器的显示方法:
format.pdf do
render :pdf => "report",
:template => "/quarters/report.pdf.erb",
end
我的 /quarters/report.pdf.erb 文件看起来就像在我的 show.html.erb 中的 highcharts 一样:
<div id="testcollections" style="width: 600px;"></div>
<!-- jQuery for testing collections charts -->
<script type="text/javascript" charset="utf-8">
$(function () {
new Highcharts.Chart({
chart: { renderTo: 'testcollections' },
title: { text: 'Test Collections' },
plotOptions: {
series: {
dataLabels: {
enabled: true,
formatter: function() {
return this.y;
}
}
}
},
series: [{
name: 'Collections',
type: 'area',
color: '#5b81b4',
data: <%= Quarter.where('quarters.client_id=?', @quarter.client_id).map(&:collections) %>
},
{
name:'Average Collections',
type: 'area',
color: '#999',
data: <%= Quarter.includes(:client).group('clients.specialty', 'quarters.year', 'quarters.quarter')
.average('quarters.collections').values.map(&:to_f).to_json %>
}]
});
});
</script>
在我的显示页面中,这是下载 PDF 文件的链接:
<%= link_to 'PDF', { :action => "show", :format => :pdf } %> |
问题是图表不会呈现,它只是空白。我从这里知道你应该调用“wicked_pdf_javascript_include_tag”,但它给了我一个“未定义”的错误方法‘javascript_src_tag’”。
有什么想法吗?
I'm using Highcharts in my application to render charts. Everything works fine, except when I want to convert a page that has charts to PDF. I'm using wicked_pdf. Here is the show method my controller:
format.pdf do
render :pdf => "report",
:template => "/quarters/report.pdf.erb",
end
My /quarters/report.pdf.erb file looks like it does in my show.html.erb for highcharts:
<div id="testcollections" style="width: 600px;"></div>
<!-- jQuery for testing collections charts -->
<script type="text/javascript" charset="utf-8">
$(function () {
new Highcharts.Chart({
chart: { renderTo: 'testcollections' },
title: { text: 'Test Collections' },
plotOptions: {
series: {
dataLabels: {
enabled: true,
formatter: function() {
return this.y;
}
}
}
},
series: [{
name: 'Collections',
type: 'area',
color: '#5b81b4',
data: <%= Quarter.where('quarters.client_id=?', @quarter.client_id).map(&:collections) %>
},
{
name:'Average Collections',
type: 'area',
color: '#999',
data: <%= Quarter.includes(:client).group('clients.specialty', 'quarters.year', 'quarters.quarter')
.average('quarters.collections').values.map(&:to_f).to_json %>
}]
});
});
</script>
And in my show page this is link to download the PDF file:
<%= link_to 'PDF', { :action => "show", :format => :pdf } %> |
The problem is that the chart doesn't render, it's just blank. I know from here that you are supposed to call the "wicked_pdf_javascript_include_tag" but it gives me an error of "undefined method `javascript_src_tag'".
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来 javascript_src_tag 在 Rails 3.1 中消失了:
http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/javascript_src_tag
您可以将您对 wicked_pdf_javascript_include_tag 的调用替换为如下内容:
Looks like javascript_src_tag went away in Rails 3.1:
http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/javascript_src_tag
You can replace your call to wicked_pdf_javascript_include_tag with something like this: