forked from OpenNeo/impress
fix ClosetHanger.set_quantity to not call destroy on a new hanger; it confuses flex
This commit is contained in:
parent
7f18fe12c1
commit
d0dffd6cff
1 changed files with 18 additions and 13 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue