Skip to content

Instantly share code, notes, and snippets.

@mikecmpbll
Created March 20, 2014 15:33
Show Gist options
  • Save mikecmpbll/9666485 to your computer and use it in GitHub Desktop.
Save mikecmpbll/9666485 to your computer and use it in GitHub Desktop.
def update_inventory
if self.item_id_changed?
old_item = Item.find(self.item_id_was)
old_item.quantityInStock -= self.quantity_was
old_item.save!
elsif self.quantity_changed?
quantity_diff = self.quantity - self.quantity_was
self.item.quantityInStock += quantity_diff
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment