ruby on rails - Error parsing JSON: undefined method 'gsub' -
i'm trying parse json in javascript, i'm getting error in rails:
undefined method `gsub' #<array:0x000001054a2440>
my code follows:
<script type="text/javascript"> var stuff = <%= escape_javascript(@json) %> var json = stuff.parsejson(); alert("text"); </script>
where @json defined in controller @nodes.to_json
can please me this? getting json javascript shouldn't hard, it's taking me forever.
the code escape_javascript
is:
def escape_javascript(javascript) if javascript javascript.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { js_escape_map[$1] } else '' end end
thus, conclude @json
array.
Comments
Post a Comment