title: How to pass rails model attributes to javascript safely?
body: <p>I'm trying to pass model attributes to javascript through html like this:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    myModel = &lt;%= MyModel.all.map{|m| m.attributes}.to_json.html_safe %&gt;;
  &lt;/script&gt;
  </code></pre>
  
  <p>but, it's not safe, because one of attribute values can be a malicious string:</p>
  
  <pre><code>"&lt;/script&gt;Evil Code&lt;script&gt;"
  </code></pre>
  
  <p>How to make it safe again?</p>