Ruby json gem编码html实体 [英] Ruby json gem is encoding html entities

查看:112
本文介绍了Ruby json gem编码html实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的代码中创建了一个名为timeOffsets的哈希

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

我使用to_json在Javascript中渲染它,:

And I render it in Javascript using to_json, :

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

但我用编码的HTML实体得到它:

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};

如何阻止它对HTML实体进行编码?

How do I stop it from encoding the HTML entities?

推荐答案

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

使用原始视图助手。

这篇关于Ruby json gem编码html实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆