I have the following line:
data: <%= @product_count.to_json %>
which renders:
data: [["name1",20],
["name2",9],
["name3",18],
["name4",32],
["name5",28],
["name6",17],
["name7",11]]
in the view. How do I change this so I get the actual quotes instead of the HTML.
The data comes from this line:
period_registration_product.each do |key, value|
@product_count << [Product.find_by_id(key).name, value]
end
Update:
I tried: data: <%= JSON.parse(@product_count.to_json) %>
and it failed.
I ended up using: data: <%= @product_count.to_json.html_safe %>
I tried both h
and raw
and neither of those worked, however, html_safe
did it.
Not sure why, but for future travelers I'm on rails version 3.2.7.
try
data: <%= raw @product_count.to_json %>
or
data: <%= @product_count.to_json.html_safe %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With