1
0
Fork 0
forked from OpenNeo/impress

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