I have an array of hashes that consists of my product data in @product_records. I can extract the name of the product using the map function like this:
<%= @product_records.map{|x|x["Name"]} %>
which renders exactly how I want it to the page like this:
["Product1","Product2",...,"Productn"]
I want to try and pass this into a javascript variable so that I can use it with JQuery autocomplete.
var data = <%= @product_records.map{|x|x["Name"]} %>
When I try and set it though the double quotes are escaping like this:
["Product1", "Product2",...,"Productn"]
I have tried various things to try and get the quotes back (.to_json etc) but nothing seems to work. There probably a very simple answer to this but I can't find what it is.
Cheers for any help.
Some common synonyms of escape are avoid, elude, eschew, evade, and shun.
escapism; escape from reality. escapism. escape from reality.
verb (used without object), es·caped, es·cap·ing. to slip or get away, as from confinement or restraint; gain or regain liberty: to escape from jail. to slip away from pursuit or peril; avoid capture, punishment, or any threatened evil.
What Does Escape Time Mean? Escape time refers to the length of time that is available to (and necessary for) an individual to escape from a specific hazardous situation.
Use <%= raw your_variable %>
:)
When you use that variable in javascript make sure, you have single quote to execute rails code in javascript.
'<%= raw @products.to_json %>'
thanks
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