by sil3ntmac · 13y ago · 0 comments
<meta name='blah' content="<%= @data.to_json %>" />
However this has always seemed unclean to me. Does anyone else have a better, alternative method of inlining data? I'd rather not use inline scripts for the exact reason they mention.
<script type="text/json" id="mydata">
{ data: "..." }
</script>
var data = JSON.parse($('mydata').textContent)
[1] https://developer.mozilla.org/en-US/docs/HTML/Global_attribu...So just going <\/script> is enough.
<div id="data" class="{json: 'x'}"/>
you can mix actual classes with JSON, just put JSON at the end:
<div class="header inline {json: 'x'}"/>
CSS selectors will work just fine