【发布时间】:2013-02-16 13:46:06
【问题描述】:
我想将一些数据作为 html 属性发布。假设有一个rails变量
@fields = [{:name => "id", :type => :integer}]
我想在页面中发布与 jquery 的 .data() 一起使用。所以在 .html.erb 我有
<%= form_tag( {:action => 'whatever'}, {... , :"data-fields" => h(@fields.to_json)}) %>
但是在渲染时,字符串[{"name":"id","type":"integer"}] 中的引号会混淆其他属性,因为Rails form_tag 使用双引号将整个json 字符串括在双引号中。如何从 Rails 发布带有字符串的 json 作为属性?
【问题讨论】:
标签: ruby-on-rails json jquery html html-escape