In a Rails 3.1 app, how can I safely embed some JSON data into an HTML document?
Suppose I have this in a controller action:
@tags = [ {name:\"ta
Your code using just @tags.to_json works in rails3, if you enable it with:
@tags.to_json
ActiveSupport.escape_html_entities_in_json = true
Otherwise, your other option is this:
var tags_list = <%= raw @tags.to_json.gsub("", "<\\/") %>;
This saves the client having to parse the whole thing through $