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={"Introduction_to_Lists":0,"Removing_elements":693,"Joining__join_":1490}; How do I stop it from encoding the HTML entities? 回答1: timeOffsets=<%=raw @timeOffsets.to_json%> Use the raw view helper. 来源: