class Download < ApplicationRecord include PgSearch belongs_to :project has_one_attached :file enum status: { not_started: 0, pending: 1, success: 2, failure: 3 } scope :unfinished_desc_order, -> { where(status: [:not_started, :pending]).order("created_at DESC") } def self.searchable_on(fields) search_opts = { against: fields, using: { tsearch: { any_word: true, prefix: true }, trigram: {}, dmetaphone: { any_word: true }, } } send(:pg_search_scope, :search, search_opts) end searchable_on %i[name release_type] end