just in case a tag updates a label without also updating slug, keep its slug in sync

This commit is contained in:
drusepth 2022-01-10 22:39:03 -08:00
parent 145b4cfe72
commit 53ac93a362

View File

@ -2,6 +2,8 @@ class PageTag < ApplicationRecord
belongs_to :page, polymorphic: true
belongs_to :user
after_update :update_slug_to_reflect_label_changes
# Delimiter to be used wherever we want to allow submitting multiple tags in a single string
SUBMISSION_DELIMITER = ',,,|||,,,'
@ -12,4 +14,13 @@ class PageTag < ApplicationRecord
def self.icon
'label'
end
def update_slug_to_reflect_label_changes
self.update_slug! if (saved_change_to_tag? && self.tag.present?)
end
def update_slug!
new_slug = PageTagService.slug_for(self.tag)
self.update(slug: new_slug) unless new_slug == self.slug
end
end