I work with two models, Buy and the other Bidon , from the Shopping form I am selecting the drums that I have available in the stock, let's say a quantity of 100 drums, after that, I enter a new quantity with the drums that I will need, say 110 drums, what happens is that when I overcome and I keep the amount the drums stock remains with number -10 for example, what I want to achieve is that when trying to save the new drum, I miss a message or something that tells me that I can not use more of the drums that exist and obviously avoid being stored with negative values.
class Bidon
has_many :compras
end
class Compra
after_save :descontar_bidones
belongs_to :bidon
private
def descontar_bidones
self.bidon.existencias -= self.cantidad_comprada
self.bidon.save
end
end
Since thank you very much and I hope you can guide me a bit.