controller.rb
@data = {a: 1, b: 2}
@data_new = {"a": 1, "b": 2}
index.html
var arr = <%= @data %> #=> {:a =>1, :b =>2} var arr = <%= raw @data %> #=> arr = {:a => 1, :b => 2}
var arr = <%= raw @data_new %> #=> arr = {:a => 1, :b => 2}
### 使用 gem “activesupport” stringify_keys
var arr = <%= raw @data_new.stringify_keys %>
#=> arr = {"a" => 1, "b" => 2}
var arr = <%= raw @data_new.stringify_keys.to_json %>
#=> arr = {"a": 1, "b": 2}
标签:arr,hash,rails,json,var,data From: https://www.cnblogs.com/hello-ruby/p/17424611.html