繁体   English   中英

Ruby json gem正在编码html实体

[英]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={&quot;Introduction_to_Lists&quot;:0,&quot;Removing_elements&quot;:693,&quot;Joining__join_&quot;:1490};

如何停止对HTML实体进行编码?

timeOffsets=<%=raw @timeOffsets.to_json%>

使用原始视图助手。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM