Prevent using # in the stored tag name

This commit is contained in:
Jason Zimdars
2025-02-14 11:23:08 -06:00
parent b54103cdef
commit edd7e55313
2 changed files with 4 additions and 1 deletions
@@ -3,7 +3,8 @@ class Taggings::TogglesController < ApplicationController
def create
if params[:tag_title].present?
@bubble.toggle_tag Current.account.tags.create!(title: params[:tag_title])
sanitized_title = params[:tag_title].strip.gsub(/\A#/, "")
@bubble.toggle_tag Current.account.tags.create!(title: sanitized_title)
else
new_tag_ids = Array(params[:tag_id])
current_tags = @bubble.tags
+2
View File
@@ -6,6 +6,8 @@ class Tag < ApplicationRecord
has_many :taggings, dependent: :destroy
has_many :bubbles, through: :taggings
validates :title, format: { without: /\A#/ }
def hashtag
"#" + title
end