在 Ruby on Rails 上使用 Javascript 并编辑代码

发布于 2024-11-19 19:46:17 字数 2678 浏览 1 评论 0原文

我正在尝试修改 Javascript 中的代码。我的应用程序是用 Ruby Rails 和 Javascript 编写的。它在 Heroku 中运行。我一直在Notepadd++中修改所有内容,然后保存它,将其推入heroku,然后我看到结果。

当我想更改 Javascript 中的某些内容时,问题就出现了。我一直在一个名为 quote.js 的文件中进行更改,但是当我更改某些内容时,什么也没有发生。下面您可以看到我试图更改的代码。在这种情况下,我只是想从劳动摘要表中取出一个名为 items 的列,我将其从变量 dest 中删除,并将其放在劳动摘要的注释中。

看来我在这里所做的更改对整个应用程序没有任何影响。我是否修改了错误的文件?

这是修改 Ruby Rails 中的 javascript 代码的正确方法吗?

谢谢。

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>");
        });
    }
});

I am trying to modify a code in Javascript. My application is written is Ruby rails and Javascript. It is run in Heroku. I have been modifiying everything in Notepadd++, then I saved it, push it into heroku and then I see the results.

The problem comes when I want to change something in Javascript. I have been making changes in a file called quote.js but when I change something, nothing happens. 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.

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?

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>");
        });
    }
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗喜 2024-11-26 19:46:18

检查您尝试加载的页面上是否包含 javascript 文件 quote.js。(在 net 选项卡或 script 选项卡下使用 firefox 的 firebug 插件来检查文件是否已加载)。您需要在布局中包含 javascript。

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). You need to include javascript in your layout.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文