I am trying to pass a rails array to a javascript function. The function will then use the array values in javascript so I need to keep it an array.
Here is how I am passing my array:
"graphit([<%=@mpg_values.join(",") %>])"
This produces this in the HTML
"graphit([#<Mile:0x6ff0cf0>,#<Mile:0x6ff0c18>,#<Mile:0x6ff0b58>])"
Which are not the values, they should be decimal numbers. I assume this is because it is a reference to the array so that I why I am getting the messed up values. If I do something like to_s I see the values but it has other stuff like the table and filed name in there as well.
Anybody know how I can get this rails array to a javascript function as an array?
Thanks in advance for any help.
Since this still seems like an issue and nobody resolved it. Here goes
var js_array = [<%= raw @object.to_json %>];
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