ruby - Javascript Rails JSON Problem -


i have large json rails controller:

@json = {:nodes => @nodes.as_json(:only => [:id, :lat, :lon])} 

and want use in javascript in views. in larger scope, want use json retrieve lat , lon's plot on google map. however, right now, i'm trying see if can points properly. question is:

what's way parse json in javascript file? (note: file's extension still html.erb) i've tried:

var stuff = eval('(' + <%= @json %> + ')');  

but doesn't seem working. can help? much!

since json legal javascript syntax, this:

var stuff = <%= @json_hash.to_json %>; 

simplest thing possibly work. if getting json untrusted source, it's better use library function parse it, prevent executing code. also, sure call to_json on final hash. don't want to_s it, default in erb.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -