使用ChartKickjs与Sinatra和HAML

时间:2014-07-06 16:11:09

标签: ruby-on-rails ruby sinatra haml chartkick

我正在尝试在ChartKick应用中使用Sinatra。当尝试创建控件(如条形图)时,我收到错误说明

  {p> cash => 82,:securities => 58}的

未定义方法`id':哈希文件:   buffer.rb位置:parse_object_ref行:323

有关解决此问题的任何建议吗?

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'}

1 个答案:

答案 0 :(得分:2)

根据haml docs:

%barchart[@estimates]

将尝试创建<barchart> html标记并使用@estimates设置其ID和类。

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

我认为你想要达到的目的是:

= bar_chart @estimates