Render jQuery in wicked_pdf

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?

Answers


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:

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

Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.