Created
February 27, 2017 11:15
-
-
Save leylaKapi/656fb1f68e44fe786506bceef955832a to your computer and use it in GitHub Desktop.
trigger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
after_save :update_subtotal | |
def calc_subtotal | |
order_items.includes(:model).collect {|oi| oi.valid? ? (oi.unit_price.to_f) : 0}.sum | |
end | |
def update_subtotal | |
self.update_column(:subtotal, calc_subtotal) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment