I’m trying to pass model attributes to javascript through html like this:
<script type="text/javascript">
myModel = <%= MyModel.all.map{|m| m.attributes}.to_json.html_safe %>;
</script>
but, it’s not safe, because one of attribute values can be a malicious string:
"</script>Evil Code<script>"
How to make it safe again?
I’ve decided to make a helper function, which escapes each attribute with
hmethod: