You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
677 B

8 years ago
8 years ago
  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('name like ?', pattern).order(:name).limit(limit)
  22. end
  23. end
  24. end