add validation to tag name (#4194)
This commit is contained in:
parent
27b2355738
commit
a49be27145
2 changed files with 21 additions and 2 deletions
|
@ -12,9 +12,10 @@
|
|||
class Tag < ApplicationRecord
|
||||
has_and_belongs_to_many :statuses
|
||||
|
||||
HASHTAG_RE = /(?:^|[^\/\)\w])#([[:word:]_]*[[:alpha:]_][[:word:]_]*)/i
|
||||
HASHTAG_NAME_RE = '[[:word:]_]*[[:alpha:]_][[:word:]_]*'
|
||||
HASHTAG_RE = /(?:^|[^\/\)\w])#(#{HASHTAG_NAME_RE})/i
|
||||
|
||||
validates :name, presence: true, uniqueness: true
|
||||
validates :name, presence: true, uniqueness: true, format: { with: /\A#{HASHTAG_NAME_RE}\z/i }
|
||||
|
||||
def to_param
|
||||
name
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue