Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 获得;(匿名功能)“;终端中的错误_Jquery_Ruby On Rails_Ruby_Jsapi - Fatal编程技术网

Jquery 获得;(匿名功能)“;终端中的错误

Jquery 获得;(匿名功能)“;终端中的错误,jquery,ruby-on-rails,ruby,jsapi,Jquery,Ruby On Rails,Ruby,Jsapi,我正在尝试使用此工具在rails应用程序中实现速度计 但我有以下错误 Uncaught ReferenceError: google is not defined (anonymous function) 这是我的示例咖啡脚本代码 $(document).ready -> drawChart = -> data = google.visualization.arrayToDataTable([ [ 'Label'

我正在尝试使用此工具在rails应用程序中实现速度计

但我有以下错误

Uncaught ReferenceError: google is not defined
(anonymous function)
这是我的示例咖啡脚本代码

$(document).ready ->
  drawChart = ->
      data = google.visualization.arrayToDataTable([
        [
          'Label'
          'Value'
        ]
        [
          'Memory'
          80
        ]
        [
          'CPU'
          55
        ]
        [
          'Network'
          68
        ]
      ])
      options = 
        width: 400
        height: 120
        redFrom: 90
        redTo: 100
        yellowFrom: 75
        yellowTo: 90
        minorTicks: 5
      chart = new (google.visualization.Gauge)(document.getElementById('widget-inner'))
      chart.draw data, options
      setInterval (->
        data.setValue 0, 1, 40 + Math.round(60 * Math.random())
        chart.draw data, options
        return
      ), 13000
      setInterval (->
        data.setValue 1, 1, 40 + Math.round(60 * Math.random())
        chart.draw data, options
        return
      ), 5000
      setInterval (->
        data.setValue 2, 1, 60 + Math.round(20 * Math.random())
        chart.draw data, options
        return
      ), 26000
      return
    
    google.load 'visualization', '1.0', 'packages': [ 'gauge' ]
    google.setOnLoadCallback drawChart
    
这是我的index.html.haml文件,我试图在其中添加给定的车速表

.content-container.widgets-container
  %h2 "This is Client Manager Dashboad page"
  = link_to "Add New Widget", admin_widgets_path, :class => "btn btn-info"
  .widgets-wrapper
    #widget-1.col-sm-4
      .widget-inner#widget-inner
我还在布局中添加了jsapi脚本文件

<script type="text/javascript" src="https://www.google.com/jsapi"></script>

有人能告诉我如何解决这个错误吗


我使用的是rails 3.2.11ruby 1.9.3

$(文档)启动时,jsapi脚本似乎还没有完成加载。准备好了并不意味着所有的东西都装好了。将jsapi脚本包含放在
$(document).ready
脚本之前。

在开始使用
google
函数之前,似乎没有加载jsapi。从片段中很难看出为什么会发生这种情况。在使用google函数之前,是否有办法确保jsapi已加载?