每次查看我都可以获得一个成功的 Open Flash Chart。我现在尝试支持每个视图的多个 Open Flash 图表,但源代码显示两个生成的 div 的 id 是相同的:
# javascript at top of view
<%= javascript_include_tag "swfobject.js", :cache => true %>
# view itself
<%= @graph.html_safe %> # html_safe is necessary for Rails 3
<%= @graph2.html_safe %>
# view's source code
<div id='flashcontent_913000'></div>
<script type="text/javascript">
swfobject.embedSWF(
"/open-flash-chart.swf","flashcontent_913000",
"440", "310", "9.0.0", "expressInstall.swf",
{"data-file":"/analytics%2Fpie1"}, {}, {} );
</script>
</div>
<br />
<div id='flashcontent_913000'></div>
<script type="text/javascript">
swfobject.embedSWF(
"/open-flash-chart.swf","flashcontent_913000",
"440", "310", "9.0.0", "expressInstall.swf",
{"data-file":"/analytics%2Fpie2"}, {}, {} );
</script>
</div>
#controller
respond_to do |wants|
wants.html {
@graph = ofc2( 440, 310, 'analytics/pie1' )
@graph2 = ofc2( 440, 310, 'analytics/pie2' )
}
end
def pie1
... # functioning when put in the view alone
end
def pie2
... # functioning when put in the view alone
end
由于 id 相同,<%= @graph.html_safe %>
尝试渲染 graph2 并失败,并且 graph2 根本不显示。我需要让 OFC2 生成不同的 ID。我怎样才能做到这一点?