![](/img/trans.png)
[英]Why is my embedded ruby json string encoded with html entities when parsed in the view?
[英]Ruby json gem is encoding html entities
我在代码中创建了一个名为timeOffsets的哈希
@timeOffsets = Hash.new
total=0
@sections.each do |i|
@timeOffsets[i.shortcode] = total
total+=i.length
end
然后使用to_json在Javascript中渲染它:
timeOffsets=<%=@timeOffsets.to_json%>;
但是我得到了编码的HTML实体:
timeOffsets={"Introduction_to_Lists":0,"Removing_elements":693,"Joining__join_":1490};
如何停止对HTML实体进行编码?
timeOffsets=<%=raw @timeOffsets.to_json%>
使用原始视图助手。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.