【发布时间】:2022-01-15 16:01:53
【问题描述】:
我有一个简单的 Rails 应用程序。我正在尝试计算服务模型中 Instruments 的每次使用时间。如何在服务模型中计算它?
class Service < ApplicationRecord
has_many :instruments
def total_usage
# I want to sum the usage arrays which is from the Instrument model.
# Here
end
end
class Instrument < ApplicationRecord
belongs_to :service, dependent: :destroy
def usage
outtime = self.out_time
intime = self.in_time
usage = ((outtime - intime)/60.0).round.abs
end
end
【问题讨论】:
标签: ruby-on-rails ruby rails-activerecord