airblade/chartjs-ror

turbolinks and ajax not working

Closed this issue · 1 comments

I'm using turbolinks, and trying to render a partial via ajax and js.erb. The initChart method never gets called, so the chart never shows up.

I have in my .js.erb

$('#loading_top_links').html('');
<% if @top_links.to_a.any? %>
$('#top_links').html('<%= escape_javascript render(partial: 'links/top_link', collection: @top_links, as: :top_link) %>');
$('#top_links_chart').html('<%= escape_javascript render(partial: 'links/top_links_chart', locals: {chart_data: @chart_data}) %>');
initChart();
<% else %>
$('#top_links_wrapper').html('<div class="panel radius callout"><p>You do not have any clicks to display</p></div>');
<% end %>

As you can see i'm trying to call initChart after the chart partial gets rendered, but its not doing anything. I don't think the initChart is even being called.

Does anyone have a good solution to using this gem with turbolinks and ajax?

Please see the discussion in #20.