2
我有红宝石的哈希持有我想输入一个JavaScript函数如何使用红宝石哈希作为一个选项javascript函数
我的哈希值是(因为它在IRB打印)选项
@options = [{:source=>"2", :tries=>"3"}]
我的javascript函数接受像
myFunc({source: num, tries: num})
因此,如果某个js.erb文件我做
选项这将导致
{:source=>\"2\", :tries=>\"3\"}
做j @edges.to_json
导致
\"{:source=>\\\"2\\\", :target=>\\\"3\\\"} }\"
在
\"{:source=>\\\"2\\\", :target=>\\\"3\\\"}\"
做j @edges.to_json.html_safe
结果有没有办法让它输出更多的JavaScript友好的哈希?
试@options [0] .to_json – 2013-03-19 15:32:17
的内容正在被scaped,尝试'@ options.to_json.html_safe' – nicooga 2013-03-19 15:34:39