I\'ve tried everything. Every combination of the helpers raw
, html_safe
to_json
including some attempts with ::JSON.encode
Since ActiveSupport 2.3.3 you have been able to do .as_json
Try this with utility method
var campaignData<%=h " =#{raw @campaign.to_json}" if @campaign %>;
Did you try escape_javascript
?
Here is an example from the *.haml file, which I just added to test my answer.
:javascript
var foo=$.parseJSON("#{j @albums.to_json}")
Where j
is an short alias for escape_javascript
.
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.