Does not list tags with an underscore at the end
This commit is contained in:
parent
2f88e910b6
commit
56f1f13683
1 changed files with 10 additions and 0 deletions
|
@ -41,6 +41,8 @@ class Tag < ApplicationRecord
|
||||||
scope :recently_used, ->(account) { joins(:statuses).where(statuses: { id: account.statuses.select(:id).limit(1000) }).group(:id).order(Arel.sql('count(*) desc')) }
|
scope :recently_used, ->(account) { joins(:statuses).where(statuses: { id: account.statuses.select(:id).limit(1000) }).group(:id).order(Arel.sql('count(*) desc')) }
|
||||||
scope :matches_name, ->(term) { where(arel_table[:name].lower.matches(arel_table.lower("#{sanitize_sql_like(Tag.normalize(term))}%"), nil, true)) } # Search with case-sensitive to use B-tree index
|
scope :matches_name, ->(term) { where(arel_table[:name].lower.matches(arel_table.lower("#{sanitize_sql_like(Tag.normalize(term))}%"), nil, true)) } # Search with case-sensitive to use B-tree index
|
||||||
|
|
||||||
|
before_save :set_unlistable, if: :force_unlistable?
|
||||||
|
|
||||||
update_index('tags#tag', :self)
|
update_index('tags#tag', :self)
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
|
@ -65,6 +67,10 @@ class Tag < ApplicationRecord
|
||||||
|
|
||||||
alias trendable? trendable
|
alias trendable? trendable
|
||||||
|
|
||||||
|
def force_unlistable?
|
||||||
|
name.end_with?('_')
|
||||||
|
end
|
||||||
|
|
||||||
def requires_review?
|
def requires_review?
|
||||||
reviewed_at.nil?
|
reviewed_at.nil?
|
||||||
end
|
end
|
||||||
|
@ -148,6 +154,10 @@ class Tag < ApplicationRecord
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_unlistable
|
||||||
|
self.listable = false
|
||||||
|
end
|
||||||
|
|
||||||
def validate_name_change
|
def validate_name_change
|
||||||
errors.add(:name, I18n.t('tags.does_not_match_previous_name')) unless name_was.mb_chars.casecmp(name.mb_chars).zero?
|
errors.add(:name, I18n.t('tags.does_not_match_previous_name')) unless name_was.mb_chars.casecmp(name.mb_chars).zero?
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue