在wicked_pdf中渲染jQuery [英] Render jQuery in wicked_pdf

查看:86
本文介绍了在wicked_pdf中渲染jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用Highcharts来渲染图表。一切正常,除非我想将包含图表的页面转换为PDF。我正在使用 wicked_pdf 。以下是我的控制器的show方法:

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

我/宿舍/报告.pdf.erb文件看起来像我的show.html.erb中的highcharts:

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>

在我的展示页面中,这是下载PDF文件的链接:

And in my show page this is link to download the PDF file:

<%= link_to 'PDF', { :action => "show", :format => :pdf } %> |

问题是图表不呈现,它只是空白。我从这里知道您应该调用wicked_pdf_javascript_include_tag,但它给出了一个错误undefined方法`javascript_src_tag'。

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'".

有什么想法吗?

推荐答案

看起来就像javascript_src_tag在Rails 3.1中消失了:
http://apidock.com/rails / ActionView / Helpers / AssetTagHelper / javascript_src_tag

Looks like javascript_src_tag went away in Rails 3.1: http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/javascript_src_tag

您可以用以下内容替换您对wicked_pdf_javascript_include_tag的调用:

You can replace your call to wicked_pdf_javascript_include_tag with something like this:

<script type="text/javascript" src="file://#{Rails.root.join('public','javascripts','highcharts.js')}"></script>

这篇关于在wicked_pdf中渲染jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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