From 4d0c72f3b1cfba43ef9f414a6c3f07fa1cff960f Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 10 Nov 2014 13:22:00 -0600 Subject: [PATCH] Stop freaking out if we try to remove a closet hanger but it's already dropped from search --- app/models/closet_hanger.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/models/closet_hanger.rb b/app/models/closet_hanger.rb index d47cd035..6a608c88 100644 --- a/app/models/closet_hanger.rb +++ b/app/models/closet_hanger.rb @@ -42,9 +42,19 @@ class ClosetHanger < ActiveRecord::Base if Flex::Configuration.hangers_enabled flex.parent :item, 'item' => 'closet_hanger' - flex.sync self + flex.sync self, callbacks: [:save] # we handle destroy more carefully end - + + after_destroy do + begin + flex.remove + rescue Flex::HttpError + # This usually means that the record was already dropped from + # the search engine. Weird, but okay; if the search engine is + # erroneously in the correct state, let it be. + end + end + def flex_source { :user_id => user_id,