简体   繁体   English

在轨道上的 Ruby 上使用 Javascript 并编辑代码

[英]Using Javascript on Ruby on rails and editing the code

I am trying to modify a code in Javascript.我正在尝试修改 Javascript 中的代码。 My application is written is Ruby rails and Javascript.我的应用程序是 Ruby 导轨和 Javascript。 It is run in Heroku.它在 Heroku 中运行。 I have been modifiying everything in Notepadd++, then I saved it, push it into heroku and then I see the results.我一直在修改 Notepadd++ 中的所有内容,然后我保存它,将其推送到 heroku 中,然后我看到了结果。

The problem comes when I want to change something in Javascript.当我想更改 Javascript 中的某些内容时,问题就来了。 I have been making changes in a file called quote.js but when I change something, nothing happens.我一直在一个名为 quote.js 的文件中进行更改,但是当我更改某些内容时,什么也没有发生。 Below you can see the code I am trying to change.您可以在下面看到我要更改的代码。 I this case I am just trying to take out a column called items from the labour summary table, I removed it from the variable dest and I put it in comments in labour summary.在这种情况下,我只是想从劳动汇总表中取出一个名为 items 的列,我将其从变量 dest 中删除,然后将其放在劳动汇总的注释中。

It seems that the changes I make here have not any effect on the whole application.看来我在这里所做的更改对整个应用程序没有任何影响。 Am I modifying the wrong file?我是否修改了错误的文件?

Is this the right way to modify the javascript code in Ruby rails?这是在 Ruby 导轨中修改 javascript 代码的正确方法吗?

Thanks.谢谢。

var labour_summary = $(labour_line_items).inject({}, function(sum){
            var key = this.pieceIdentifier();
            var added = this.pieceSummary();
            if(typeof sum[key] == 'undefined') {
                // New material in summary
                sum[key] = added;
            } else {
                // Add quantity to summary
                sum[key].hours  += added.hours;
                sum[key].cost   += added.cost;
                //sum[key].item += ", " + added.item;
            }
            return sum;
        });


        var dest = this.labour_summary_table;
        $("tr:gt(0)", dest).remove();
        $.each(labour_summary, function() {
            dest.append("<tr><td>" + [$.round_two(this.hours), $.dollars(this.hourly_rate), $.dollars(this.cost)].join("</td><td>") + "</td></tr>");
        });
    },
    updateCustomSummary: function(e) {
        var custom_line_items = this.activeQuoteItems().inject([], function(is) { 
                return $.merge(is, $(this).obj().activeCustomLineItems().get()); // grab this quote items labour line items
            }).collect( function() {    
                return $(this).obj();                                       // extend the array and collect the labour line item objects
            });

        var custom_summary = $(custom_line_items).inject({}, function(sum){
            var key = this.pieceIdentifier();
            var added = this.pieceSummary();
            if(typeof sum[key] == 'undefined') {
                // New material in summary
                sum[key] = added;
            } else {
                // Add quantity to summary
                sum[key].quantity   += added.quantity;
                sum[key].cost       += added.cost;
                //sum[key].item     += ", " + added.item;
            }
            return sum;
        });

        var dest = this.custom_summary_table;
        $("tr:gt(0)", dest).remove();
        $.each(custom_summary, function() {
            dest.append("<tr><td>" + [this.customName, this.quantity, $.dollars(this.costPerPiece), $.dollars(this.cost), this.item].join("</td><td>") + "</td></tr>");
        });
    }
});

Check if you are including the javascript file quote.js on the page you are trying to load.(Use firebug addon for firefox under net tab or script tab to check if the file is loaded or not).检查您是否在尝试加载的页面上包含 javascript 文件 quote.js。(在 net 选项卡或脚本选项卡下使用 firefox 的 firebug 插件来检查文件是否已加载)。 You need to include javascript in your layout.您需要在布局中包含 javascript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM