开发者

Ruby json gem is encoding html entities

开发者 https://www.devze.com 2023-02-17 00:46 出处:网络
I make a hash called timeOffsets in my code @timeOffsets = Hash.new total=0 @sections.each do |i| @timeOffsets[i.shortcode] = total

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,&开发者_JS百科quot;Removing_elements&quot;:693,&quot;Joining__join_&quot;:1490};

How do I stop it from encoding the HTML entities?


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

Use the raw view helper.

0

精彩评论

暂无评论...
验证码 换一张
取 消