Rails Hash in javascript, access values -


i have following javascript code:

<input type="hidden" name="query_form_select_ops" id="query_form_select_ops" value='<%= schema%>'  />  <script>   function select_pk2(cell){   var val = $('#query_form_opt_'+cell+'_1').val();   var opts = $('#query_form_select_ops').val();     } </script> 

example:

schema typical ruby hash:

{    "car"=>{"col"=>"blue", "engine"=>"hhd4m"},   "train"=>{"col"=>"black", "engine"=>"8495f"} } 

the variable val has value "train" , opts whole ruby hash

to access col , engine of train in ruby: schema["train"]. how can same in javascript?
have tried:

var select = opts[val] 

but tells me var in undefined. how can access values of ruby hash in javascript given hash , 1 of keys?

dump schema hash json , parse in javascript. this:

<input type="hidden" name="query_form_select_ops" id="query_form_select_ops" value='<%= schema.to_json %>'  /> 

and script:

function select_pk2(cell){   var val = $('#query_form_opt_'+cell+'_1').val();   var opts = json.parse($('#query_form_select_ops').val());   } 

this way should able access values in way want.

each individual value of hash in example hash well, can access them using proper keys. this:

opts['car']['col']; 

Comments