Print valid, non-escaped JSON in a view with Rails

前端 未结 4 595
春和景丽
春和景丽 2021-01-02 00:29

I\'ve tried everything. Every combination of the helpers raw, html_safe to_json including some attempts with ::JSON.encode

4条回答
  •  执念已碎
    2021-01-02 01:03

    The problem here is with the "=" string. As it's considered unsafe, it taints the other string.

    You can probably do either:

    raw("=" + @campaign.to_json)
    

    or

    "= #{@campaign.to_json}".html_safe
    

    which are roughly the same.

提交回复
热议问题