Someone please help with this!!!
I'm trying to simply parse my json object in javascript within rails, and NOTHING seems to work.
The story is in the controller is:
def map
@nodes = Node.all
@json = {"Nodes" => @nodes.as_json(:only => [:ID, :Lat, :Lon])}
end
In my view, I have simple javascript:
<script type="text/javascript">
var stuff = <%= @json %>;
var json = JSON.parse(stuff);
alert("text");
</script>
I'm just trying to see if the code runs through the first two lines with alert message, but it never works, always throwing me a unexpected token error (usually a colon or a { ). I've also tried doing the eval method, but that also doesn't work. Can someone please help me parse the json in the javascript? I would be eternally grateful....