In a rails app I have an object defined in a controller containing an icon and some values:
@data = "<i class='fa fa-circle fa-lg'></i><span>Speed: </span> #{b.speed.to_f} | Time: #{b.gps_date.try(:strftime, '%-m/%e %H:%M')}} <br />".html_safe.to_json
In view I parse it like this:
<script>
var data = JSON.parse('<%= raw @data.as_json %>');
</script>
But I get the following error:
Uncaught SyntaxError: missing ) after argument list
I works fine when I remove the icon code that contains the single quotes for class
<i class='fa fa-circle fa-lg'></i>
How can I fix this error?
to_jsonandas_json?to_jsonand then parsed the json in JS'<%= raw @data %>'should work. Have you tried ?