I have a Javascript object in a partial that looks like this:
_chart.js.erb
{
chart: {
animation: <%= @animation %>
},
plotOptions: {
...
This partial works as expected as part of a view.
I need to convert it to JSON to be used as a config for a command line utility.
What is a good way to load the partial, interpolate the ERB, convert to JSON and return the JSON?
Something like this might work, but seems like a poor solution:
respond_to do |format|
format.json {
js = File.read('app/views/trades/_chart.js.erb')
hsh = eval(ERB.new(js).result)
parsed = JSON.parse(hsh)
render json: parsed.to_json
}
let data = <%= raw @serialized_data.to_json %>;instead.