0

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?

  • 4
    I would need to look into chartkick further if this isn't the fix, but restart your Rails server and try again. – Justin Apr 23 '14 at 13:30
  • @Justin hahaha, always the simple things, why don't you post that as an answer so people don't stumble across this question and think it's unsolved. – Mike H-R Apr 24 '14 at 06:05

2 Answers2

0

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

Justin
  • 4,922
  • 2
  • 27
  • 69
0

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.

Jono
  • 3,393
  • 6
  • 33
  • 48