How to safely embed JSON with [removed] in HTML document?

后端 未结 4 1930
陌清茗
陌清茗 2020-12-30 01:16

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         


        
4条回答
  •  醉梦人生
    2020-12-30 01:23

    I think that if you try this it will work:

    var tags_list = "<%== @tags.to_json.gsub('/', '\/') %>";
    

    (Notice the double == and the " ")

提交回复
热议问题