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.
 
 
 
 
 

19 lines
601 B

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