From 3b024c563c92ecb1221309274ba18c8cc65c2ab8 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 30 Oct 2022 02:43:20 +0200 Subject: [PATCH] Fix not being able to input featured tag with `#` (#19535) --- app/models/featured_tag.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/featured_tag.rb b/app/models/featured_tag.rb index 3f5cddce6..d4ed74302 100644 --- a/app/models/featured_tag.rb +++ b/app/models/featured_tag.rb @@ -19,6 +19,8 @@ class FeaturedTag < ApplicationRecord validate :validate_tag_name, on: :create validate :validate_featured_tags_limit, on: :create + before_validation :strip_name + before_create :set_tag before_create :reset_data @@ -48,6 +50,12 @@ class FeaturedTag < ApplicationRecord private + def strip_name + return unless defined?(@name) + + @name = @name&.strip&.gsub(/\A#/, '') + end + def set_tag self.tag = Tag.find_or_create_by_names(@name)&.first end