class Asset < ApplicationRecord has_one_attached :file include PgSearch::Model pg_search_scope :pg_search, against: [:title], associated_against: { file_blob: [:filename, :content_type] }, using: { tsearch: { prefix: true } } scope :by_last_modified, ->(rev) { order(updated_at: rev ? :asc : :desc, id: rev ? :desc : :asc) } scope :by_filename, ->(rev) { order(title: rev ? :desc : :asc) } scope :simple_search, ->(q) { pg_search(q) unless q.blank? } end