diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2022-10-30 02:43:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-30 02:43:20 +0200 |
commit | 3b024c563c92ecb1221309274ba18c8cc65c2ab8 (patch) | |
tree | 3f4b6f7f8121f1e2f128f8e0e801d5ff1d2b8a9d | |
parent | ad83e64795361dc9d5990a9dae4f91a3642109a0 (diff) |
Fix not being able to input featured tag with `#` (#19535)
-rw-r--r-- | app/models/featured_tag.rb | 8 |
1 files changed, 8 insertions, 0 deletions
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 |