mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
just in case a tag updates a label without also updating slug, keep its slug in sync
This commit is contained in:
parent
145b4cfe72
commit
53ac93a362
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user