Controllers, views, helpers, and javascript

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Controllers, views, helpers, and javascript

Jussi Hirvi
I am doing charts with and basically my
installation already works. However, I can access the chart js libraries
only from views. In a view I can say pie_chart (with parameters), and I
will get a nice pie chart.

But I would like to compose the page html in controllers so I would not
need to enclose every damn line in <% %>. But for controllers, the graph
suite's command pie_chart is a "command not found".

Then I tried a helper,  and calling the helper's method:

def piechart_test
     pie_chart({"a" => 4, "b" => 5, "c" => 7})

  in a controller. Partial success. I get the following output:

<div id="chart-1" style="height: 400px;width: 100%;text-align:
center;color: #999;line-height: 400px;font-size: 14px;font-family:
'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica,
   new Chartkick.PieChart("chart-1", {"a":4,"b":5,"c":7},

It says "Loading...", but it never loads. Whereas if I call the same
helper method from the view, the graph loads ok.

I could now move my whole html composition from the controller to a
helper, and then call that from the view. A downside is that helpers are
not namespaced, so it would feel a less clean solution.

Tips would be appreciated! BTW, Rails 5.x.

- Jussi

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit
For more options, visit