Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.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
Ruby on rails RubyonRails计算总和 身份证件 什一税 要约 誓言 全部的 1. 120 230 280 ???_Ruby On Rails - Fatal编程技术网

Ruby on rails RubyonRails计算总和 身份证件 什一税 要约 誓言 全部的 1. 120 230 280 ???

Ruby on rails RubyonRails计算总和 身份证件 什一税 要约 誓言 全部的 1. 120 230 280 ???,ruby-on-rails,Ruby On Rails,使用sum: Record.where(id:1).sum('tithe+要约人+质押') 非常感谢这张桌子是真的吗?总计实际上是一列吗?如果是这种情况,我只需在保存前添加一个值,以计算保存前的合计:计算合计;def计算_总数;self.total=[self.tithe,self.offertory,self.质押].reduce(0.0){| m,e | m+e.to_f}。如果表中不包含此列,则可以在modeldef total中创建一个方法@total | |=[self.tithe,s

使用sum:

Record.where(id:1).sum('tithe+要约人+质押')

非常感谢这张桌子是真的吗?总计实际上是一列吗?如果是这种情况,我只需在保存前添加一个值,以计算保存前的合计
:计算合计;def计算_总数;self.total=[self.tithe,self.offertory,self.质押].reduce(0.0){| m,e | m+e.to_f}
。如果表中不包含此列,则可以在model
def total中创建一个方法@total | |=[self.tithe,self.offertory,self.质押].减少(0.0){| m,e | m+e.to_f}
或查询
记录中的虚拟属性。选择('records.*,records.tithe+records.offertory+records.offertory+records.质押as total')