Skip to content
Advertisement

Total value of warehouse active record

I have the object Tool and I need to calculate the cost of all the Tools in the warehouse. I can sum the column price Tool.sum(:price) but i need to sum (quantity * price) of all the table Tools. Thanks in advance.

Advertisement

Answer

Check out the example listed for ActiveRecord::Calculations#calculate.

You can do the following:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement