Rails部分不使用JavaScript呈现

时间:2012-06-27 15:52:54

标签: ruby-on-rails ruby-on-rails-3 highcharts activeadmin partial

我正在尝试在我的应用中渲染部分,但由于某种原因它不会渲染。我认为它与我的资产管道有关,而且我没有正确实现我想在部分中使用的JavaScript。使用简单句子的测试部分工作得很好。有人可以指导我在我的应用程序中正确使用JavaScript吗?

以下是我要展示的内容: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>

谢谢!

2 个答案:

答案 0 :(得分:0)

在javascript代码之前添加:

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

P.S。除此之外,最好将javascript包含在部分内容中或使用content_for

答案 1 :(得分:0)

我刚刚在TextEdit中重新创建了该文件,并且它有效。出于某种原因,TextMate秘密地将其添加到文件中:&#8203;

相关问题