Question

After reading http://chartkick.com/ I've tried to add chart to my website Gemfile:

...  
gem 'chartkick'
...

index.html.erb:

<%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %>
<%= pie_chart({"Football" => 10, "Basketball" => 5}) %>
<h1>Hello, Rails!</h1>

assets/javascript/application.js:

//= require chartkick
//= require jsapi
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .

But all I've got is:

undefined method `pie_chart' for #<#:0x4e49bd8>

I use chartkick (1.2.4), ruby(1.9.3), rails (4.1.0). What should I do?

Was it helpful?

Solution

I would need to look into chartkick further if this isn't the fix, but restart your Rails server and try again.

OTHER TIPS

I had the same issue, for Chartkick to work I had to put the:

<%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %>

in the the application.html.erb file only not the index file, under the head attribute

<head> 
   ...
   <%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %> 
</head> 

And it was then usable in the whole application, we also found it to be more reliable when it was in the application.html.erb file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top