0

I'm trying to use ChartKick in my Sinatra application. When trying to create a control such as a barchart I get an error stating

undefined method `id' for {:cash=>82, :securities=>58}:Hash file: buffer.rb location: parse_object_ref line: 323

Any suggestions on resolving this?

app.rb

...
 @estimates = {:cash => cash_estimate, :securities=> sec_estimate}
haml :results
...

results.haml

%label="By saving cash you will be able to retire at the age of  #{@estimates[:cash]}}."
%br
%label="Choosing to invest your savings in stock securities may allow you to retire at #{@estimates[:securities]}."

%barchart[@estimates]

%script{:type => 'text/javascript', :src => '//www.google.com/jsapi'}
%script{:type => 'text/javascript', :src => '/js/chartkick.js'}
Antarr Byrd
  • 24,863
  • 33
  • 100
  • 188
  • Also, you can omit the `=` and double quotes on your labels. The variable will be interpolated anyway. http://haml.info/docs/yardoc/file.REFERENCE.html#ruby_interpolation_ – mus Jul 06 '14 at 16:48
  • @mus thanks for the advice. I'm rather new to ruby so always looking to make my code look more ruby – Antarr Byrd Jul 06 '14 at 16:49

1 Answers1

2

According to haml docs this:

%barchart[@estimates]

Will try to create a <barchart> html tag and use @estimates to set its id and class.

http://haml.info/docs/yardoc/file.REFERENCE.html#object_reference_

What I think you are trying to achieve is this:

= bar_chart @estimates
Antarr Byrd
  • 24,863
  • 33
  • 100
  • 188
mus
  • 499
  • 2
  • 6