0

我試圖在我的應用中呈現部分內容,但由於某種原因它不會呈現。我認爲這與我的資產管道有關,而且我沒有正確實現我想在我的部分中使用的JavaScript。一個簡單句子的測試部分工作得很好。有人可以指導我在我的應用程序中正確使用JavaScript嗎?Rails部分未使用JavaScript呈現

這裏是我試圖表現出的jsfiddle:http://jsfiddle.net/yZQg4/

有問題的部分:

<%= javascript_include_tag "highcharts", "exporting", "jquery-1.4.2.min", "rails" %> 

<script type="text/javascript" charset="utf-8"> 
    $(function() { 
    var chart; 
    $(document).ready(function() { 
     chart = new Highcharts.Chart({ 
      chart: { 
       renderTo: 'panel_contents', 
       type: 'column' 
      }, 

      xAxis: { 
       categories: ['Automotive', 'Agency', 'Contractor', 'Country Club', 'Other'] 
      }, 
      yAxis: { 
       min: 0, 

       title: { 
        text: 'Business Summary' 
       }, 
       stackLabels: { 
        enabled: true, 
        style: { 
         fontWeight: 'bold', 
         color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray' 
        } 
       } 
      }, 
      legend: { 
       align: 'right', 
       x: 100, 
       verticalAlign: 'top', 
       y: 0, 
       floating: true, 
       backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white', 
       borderColor: '#CCC', 
       borderWidth: 1, 
       shadow: false 
      }, 
      tooltip: { 
       formatter: function() { 
        return '<b>' + this.x + '</b><br/>' + this.series.name + ': ' + this.y + '<br/>' + 'Total: ' + this.point.stackTotal; 
       } 
      }, 
      plotOptions: { 
       column: { 
        stacking: 'normal', 
        dataLabels: { 
         enabled: true, 
         color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white' 
        } 
       } 
      }, 
      series: [{ 
       name: 'Mobile', 
       data: [5, 3, 4, 27, 2]}, 
      { 
       name: 'Foursquare', 
       data: [2, 2, 3, 2, 1]}, 
      { 
       name: 'Facebook', 
       data: [3, 4, 4, 2, 5]}, 
      { 
       name: 'Yelp', 
       data: [3, 4, 4, 2, 5]}, 
      { 
       name: 'Google', 
       data: [3, 4, 4, 2, 5]}] 
     }); 
    }); 

});​​ 
</script> 

工作測試部分:

<h1> hello world </h1> 

謝謝!

+0

當您檢查頁面時,控制檯中是否存在任何JS錯誤? – John

+0

我該如何檢查? – Slicekick

回答

0

添加JavaScript代碼在此之前:

<div id="panel_contents"></div> 

附:此外它更好地移動javascript包含部分或使用content_for

+0

我之前有過,但由於某種原因,我將其刪除。我只是包括它,但部分仍未出現。 – Slicekick

+0

將js包含到您的佈局中。 Firebug(Firefox)或Chrome控制檯是否會給你提供任何錯誤? – vlain

+0

我搬了它,並用Chrome控制檯進行檢查。這個錯誤顯示 - '未捕獲的SyntaxError:意外的令牌非法' – Slicekick

0

我剛剛在TextEdit中重新創建該文件,它的工作。出於某種原因,TextMate祕密地將其添加到文件中:&#8203;

+0

哈哈,它發生了。 – vlain