Render jQuery in wicked_pdf
-
25-10-2019 - |
Domanda
Sto usando Highcharts nella mia applicazione per la visualizzazione dei grafici. Tutto funziona bene, tranne quando voglio convertire una pagina che ha i grafici in formato PDF. Sto utilizzando wicked_pdf . Ecco il metodo show il mio controller:
format.pdf do
render :pdf => "report",
:template => "/quarters/report.pdf.erb",
end
I miei /quarters/report.pdf.erb aspetto di file, come invece accade nel mio show.html.erb per 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>
E nella mia pagina mostrare questo è link per scaricare il file PDF:
<%= link_to 'PDF', { :action => "show", :format => :pdf } %> |
Il problema è che il grafico non rende, è solo vuota. So per qui che si suppone di chiamare il "wicked_pdf_javascript_include_tag" ma mi dà un errore di "undefined metodo `javascript_src_tag '".
Qualche idea?
Soluzione
appare come javascript_src_tag andò in Rails 3.1: http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/javascript_src_tag
È possibile sostituire la chiamata a wicked_pdf_javascript_include_tag con qualcosa di simile:
<script type="text/javascript" src="file://#{Rails.root.join('public','javascripts','highcharts.js')}"></script>