我有一个红宝石函数创建一个哈希的实例变量,我有麻烦accesing它的JavaScript内的值。嵌入红宝石的JavaScript,红宝石不承认
这是我的控制器:
class TransferController < ApplicationController
def index
require 'json'
#@transfers = Transfer.select("transfer_id,section_id,sum(net) as net").group("transfer_id,section_id").having("sum(net) <> ?",0).order("transfer_id ASC")
@transfers = Transfer.select("section_id,section_name,sum(net) as net").group("section_id,section_name").order("section_id ASC")
h = Hash.new()
a = []
@transfers.each do |section|
h["name"] = section.section_name
h["size"] = section.net
a.insert(h)
end
@sectionhash = Hash.new()
@sectionhash["name"] = "stringush"
@sectionhash["children"] = a
end
end
,这是我的看法:
<h1><%= @sectionhash["name"] %></h1>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript">
var x = <%= @sectionhash["name"] %>;
alert(x);
</script>
的reuslt我得到的是,显示我的散列内的值,但JavaScript并没有什么。我甚至试图在Ruby代码的分配之前加入一个警报,它工作。所以它不符合嵌入式ruby。 我见过这个论坛的人回答说我写的嵌入式行是合法的。 任何想法,为什么这不工作?