fix ClosetHanger.set_quantity to not call destroy on a new hanger; it confuses flex

This commit is contained in:
Emi Matchu 2013-01-25 10:44:15 -06:00
parent 7f18fe12c1
commit d0dffd6cff

View file

@ -69,6 +69,10 @@ class ClosetHanger < ActiveRecord::Base
end
hanger = self.where(conditions).first
if quantity > 0
# If quantity is non-zero, create/update the corresponding hanger.
unless hanger
hanger = self.new
hanger.user_id = conditions[:user_id]
@ -79,13 +83,14 @@ class ClosetHanger < ActiveRecord::Base
hanger.list_id = conditions[:list_id]
end
unless quantity == 0
Rails.logger.debug("Logging to #{hanger.id} quantity #{quantity}")
hanger.quantity = quantity
hanger.save!
else
hanger.destroy if hanger
elsif hanger
# If quantity is zero and there's a hanger, destroy it.
hanger.destroy
end
# If quantity is zero and there's no hanger, good. Do nothing.
end
protected