sinatra #31

joaodrp opened this Issue Mar 20, 2012 · 4 comments


None yet
2 participants

joaodrp commented Mar 20, 2012


Is there a way to make this work with a sinatra app? Cant get it to work.


winston commented Mar 20, 2012

I have not tried this with SInatra. May I know what is not working? Thanks!

joaodrp commented Mar 20, 2012

If in my sinatra app I do something like:

      get '/' do
        data_table =
        # Add Column Headers
        data_table.new_column('string', 'Year')
        data_table.new_column('number', 'Sales')
        data_table.new_column('number', 'Expenses')
        # Add Rows and Values
                                ['2004', 1000, 400],
                                ['2005', 1170, 460],
                                ['2006', 660, 1120],
                                ['2007', 1030, 540]
        option = { width: 400, height: 240, title: 'Company Performance' }
        @chart =, option)
        erb :index

Then in my view I do:

<div id='chart'></div>
      <%= render_chart(@chart, 'chart') %>  # => render_chart is not supported in sinatra

Probably I could get this to work if I can receive the chart image url, something like:

@chart =, option).url

Then in my view I would be able to do at least this:

<div id='chart'></div>
     <img src= <%= @chart %>/>

Is it possible to make it compatible with sinatra?


winston commented Mar 20, 2012

The controller code looks correct to me, so I believe the reason it's not working is probably because render_chart does not exist in Sinatra. That method is a helper for Rails only.

Instead of using render_chart in your view, try this:

<div id='chart'></div>
<%= @chart.to_js("chart") %>

Let me know if this works. Thanks!

joaodrp commented Mar 20, 2012

Thanks, it works!

@joaodrp joaodrp closed this Mar 20, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment