Class: Maglev::Asset

Inherits:
ApplicationRecord show all
Defined in:
app/models/maglev/asset.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.search(keyword, type, page = nil, per_page = nil) ⇒ Object

class methods ##



18
19
20
21
22
23
24
25
26
# File 'app/models/maglev/asset.rb', line 18

def self.search(keyword, type, page = nil, per_page = nil)
  all
    .optimized
    .where(keyword.present? ? arel_table[:filename].matches("%#{keyword}%") : nil)
    .where(arel_table[:content_type].matches("%#{type}%"))
    .order(created_at: :desc)
    .page(page || 1)
    .per(per_page || 10)
end

Instance Method Details

#fileObject

validations ##



8
# File 'app/models/maglev/asset.rb', line 8

validates :file, presence: true

#to_paramObject

methods ##



12
13
14
# File 'app/models/maglev/asset.rb', line 12

def to_param
  "#{id}-#{File.basename(filename, '.*').parameterize}#{File.extname(filename)}"
end