After exhausting all options, trying out various helper combinations like raw
, html_safe
, and to_json
along with attempts using ::JSON.encode
and CGI.unescape
, I still can't seem to properly display well-formed JSON in my view. No matter what I try, it always ends up being HTML escaped.
This is the code snippet from my view:
var campaignData<%= "=" + (raw @campaign.to_json) if @campaign %>;
In my scenario, it's consistently the double quotes that are getting escaped as ". While I could perform a gsub on the quotes, I consider this to be a suboptimal solution for what should be a straightforward and well-documented use case.