Render jQuery in wicked_pdf

I use Highcharts in my chart rendering application. Everything works fine, except when I want to convert a chart page to PDF. I am using wicked_pdf . Here is my show method:

format.pdf do render :pdf => "report", :template => "/quarters/report.pdf.erb", end 

The file My / quarters / report.pdf.erb looks like in my show.html.erb for high maps:

  <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 on my show page, this is the link to download the PDF file:

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

The problem is that the chart is not displayed, it is just empty. I know from here that you should call "wicked_pdf_javascript_include_tag", but that gives me the error "undefined method` javascript_src_tag ".

Any thoughts?

+2
source share
1 answer

It looks like javascript_src_tag has gone into Rails 3.1: http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/javascript_src_tag

You can replace your call with wicked_pdf_javascript_include_tag like this:

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

Source: https://habr.com/ru/post/1496401/


All Articles