Last active
June 1, 2017 15:43
-
-
Save luckyruby/9b7c14694b95e60b8a3e477604f17f47 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
before_save :adjust_parts_qty | |
before_destroy :adjust_parts_qty | |
private | |
def adjust_parts_qty | |
old_quantity = quantity_was || 0 | |
new_quantity = marked_for_destruction? ? 0 : quantity | |
part.quantity += new_quantity - old_quantity | |
part.save! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment