Method: Asset.for_drawer

Defined in:
lib/forge/app/models/asset.rb

.for_drawer(params) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/forge/app/models/asset.rb', line 32

def self.for_drawer(params)
  unless params[:q].blank?
    assets = where("LOWER(assets.title) LIKE ? OR LOWER(tags.name) = ?", "%#{params[:q].downcase}%", params[:q].downcase).includes(:tags).references(:tags)
  else
    case params[:filter]
    when "images"
      assets = where("attachment_content_type LIKE ?", "%image%")
    when "documents"
      assets = where("attachment_content_type NOT LIKE ?", "%image%")
    else
      assets = self
    end
  end
  assets.limit(20).offset(params[:offset] || 0)
end