From f922e3dd8e373845bc327d5c5fd051e851510cc6 Mon Sep 17 00:00:00 2001 From: Caio <117518+caiosba@users.noreply.github.com> Date: Wed, 14 Aug 2024 15:21:35 -0300 Subject: [PATCH] Fixing Sidekiq error "ActiveRecord::RecordInvalid: Text has already been taken" --- app/models/concerns/article.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/article.rb b/app/models/concerns/article.rb index f2c11b2b18..614fa2a660 100644 --- a/app/models/concerns/article.rb +++ b/app/models/concerns/article.rb @@ -72,13 +72,13 @@ def create_tag_texts_if_needed module ClassMethods def create_tag_texts_if_needed(team_id, tags) - tags.each do |tag| + tags.to_a.map(&:strip).each do |tag| next if TagText.where(text: tag, team_id: team_id).exists? tag_text = TagText.new tag_text.text = tag tag_text.team_id = team_id tag_text.skip_check_ability = true - tag_text.save! + tag_text.save end end