patrickS patrickS - 2 months ago 4x
Ruby Question

Chartkick: How to pass parameters to the ChartsController

I have created a ChartsController, for the async JSON loading.
It is decribed here:

Everything works fine. But now I try to send a parameter to the controller how can this be done?

This is my call in the view.html.erb:

<%= line_chart test_charts_path %>

I want something like this:

<%= line_chart test_charts_path(object) %>

Is this possible?


You do realize you are just passing a link to the data in your line_chart that is the line chart will call the url to retrieve data.

So you can conveniently use route helpers like.

test_chart_path(param1: object)

and under your charts controller in test method

param1 = params[:param1] // whatever you pass comes here.