简体   繁体   中英

Ruby json gem is encoding html entities

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?

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

使用原始视图助手。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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