I have a Ruby array like this in my controller:
@location_list = [
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]
And I am catching it like this in my view:
location_list = "<%= @location_list.to_json %>";
But if I do alert(location_list), I get:
[["Mushrooms",3],["Onions",1],["Olives",1],["Zucchini",1],["Pepperoni",2]]
How do I get the correspondent object without those "?
Try:
<%= raw @location_list.as_json %>
Using to_json
will end up rendering a string, with embedded double-quotes, and would need to be JS-escaped. And it would be a string, not an array.
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