I have a Company
model and a Payment
model.
For my Company
model I whish to create a custom (class/instance?) method that performs a sumproduct of a selected company's associated attributes.
My Company
model:
def total_payments
self.payments.map { |s| s.value * s.currency }.sum
end
However if I run Company.first.total_payments
it gives me a no_method_error
.
How to I properly define my method?
It seems like all good, just reload your rails console. Rails does not apply changes in your classes immediately.