how to update listing quntity when order is made? and how to stop an order if stock = 0

i added stock value as integer to listing but i don't find the right code for this action. i tried this lines of code in order model: after_save :remove_from_stock after_destroy :return_to_stock def remove_from_stock competition.stock -= self.quantity end def return_to_stock competition.stock += self.quantity end but i'm getting this error: nil can't be coerced into Integer and if you can also help me on how to stop order if stock is 0 thank you very much and best regards Boaz

Posted over 2 years ago by boaz