打开Flash图表2 - ID是相同的,因此不显示倍数

时间:2010-10-09 09:46:03

标签: ruby-on-rails ruby-on-rails-3 open-flash-chart

我可以为每个视图获得一个成功的Open Flash Chart。 我现在尝试支持每个视图的多个Open Flash Charts,但源代码显示两个生成的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。我怎么能做到这一点?

1 个答案:

答案 0 :(得分:0)

事实证明,您可以在'analytics / pie1'之后立即在控制器中指定一个ID。通过具体指定ID,我们可以消除算法生成相同数字的可能性,从而无法显示图像。

示例:@graph = ofc2( 440, 310, 'analytics/pie1', '/', 'my_unique_div' )