Javascript 为控制台日志格式化ruby哈希字符串
我正在编写一个Rails应用程序,我有一些变量正在通过视图文件打印到浏览器控制台。特别是,我创建了一个ruby哈希,其格式如下:Javascript 为控制台日志格式化ruby哈希字符串,javascript,ruby-on-rails,Javascript,Ruby On Rails,我正在编写一个Rails应用程序,我有一些变量正在通过视图文件打印到浏览器控制台。特别是,我创建了一个ruby哈希,其格式如下: {string: [array], string: [array]} 例如,我可能有一个数组 {'nil': [1,2, 3], "124": [4,5], "124/125": [6]} 将其打印到浏览器控制台时,格式设置将关闭。例如,现在我有: {nil=>[1, 2, 3], "124"=>[4
{string: [array], string: [array]}
例如,我可能有一个数组
{'nil': [1,2, 3], "124": [4,5], "124/125": [6]}
将其打印到浏览器控制台时,格式设置将关闭。例如,现在我有:
{nil=>[1, 2, 3], "124"=>[4, 5], "124/217"=>[6]}
我怎样才能去掉添加的额外字符
这是我的实际代码:
<% allBranches = Hash.new %>
<% currentBranch = Array.new %>
<% (1..@ancestry.length-1).each do |index| %>
<% if @ancestry[index] == @ancestry[index-1] %>
<% currentBranch.push(index) %>
<% else %>
<% allBranches[@ancestry[index-1]]=currentBranch %>
<% currentBranch = Array.new %>
<% currentBranch.push(index) %>
<% end %>
<% end %>
<script type="text/javascript">
console.log("allBranches: <%=allBranches%>");
</script>
console.log(“所有分支:”);
使用html\u-safe
console.log(“所有分支:”)代码>
如果allbranchs
已经是一个字符串,则to_s
部分是多余的 使用html\u-safe
console.log(“所有分支:”)代码>
如果allbranchs
已经是一个字符串,则to_s
部分是多余的 谢谢你的帮助!我得到了散列的错误“undefined method html_safe”。哦,对了,AllBranchs不是字符串。我刚刚编辑了答案,将添加到
。谢谢你的帮助!我得到了散列的错误“undefined method html_safe”。哦,对了,AllBranchs不是字符串。我刚刚编辑了答案,将添加到
。