簡體   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