The code powering m.abunchtell.com https://m.abunchtell.com
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

30 rader
691 B

  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: tags
  5. #
  6. # id :integer not null, primary key
  7. # name :string default(""), not null
  8. # created_at :datetime not null
  9. # updated_at :datetime not null
  10. #
  11. class Tag < ApplicationRecord
  12. has_and_belongs_to_many :statuses
  13. HASHTAG_RE = /(?:^|[^\/\)\w])#([[:word:]_]*[[:alpha:]_][[:word:]_]*)/i
  14. validates :name, presence: true, uniqueness: true
  15. def to_param
  16. name
  17. end
  18. class << self
  19. def search_for(term, limit = 5)
  20. pattern = sanitize_sql_like(term) + '%'
  21. Tag.where('lower(name) like lower(?)', pattern).order(:name).limit(limit)
  22. end
  23. end
  24. end