Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement