Ruby json gem is encoding html entities

大憨熊 提交于 2019-12-08 12:24:41

问题


I make a hash called timeOffsets in my code

@timeOffsets = Hash.new
total=0
@sections.each do |i|
  @timeOffsets[i.shortcode] = total
  total+=i.length
end

And I render it in Javascript using to_json, :

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

but I get it with the HTML entities encoded:

timeOffsets={&quot;Introduction_to_Lists&quot;:0,&quot;Removing_elements&quot;:693,&quot;Joining__join_&quot;:1490};

How do I stop it from encoding the HTML entities?


回答1:


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

Use the raw view helper.



来源:https://stackoverflow.com/questions/5307495/ruby-json-gem-is-encoding-html-entities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!