Class: Dorsale::Alexandrie::AttachmentsSorter

Inherits:
Agilibox::Sorter
  • Object
show all
Defined in:
app/sorters/dorsale/alexandrie/attachments_sorter.rb

Instance Method Summary collapse

Instance Method Details

#sortObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/sorters/dorsale/alexandrie/attachments_sorter.rb', line 2

def sort
  case column
  when :created_at, :updated_at
    {column => direction}
  when :name
    Arel.sql %(LOWER(#{model.table_name}.#{column}) #{direction})
  when :attachment_type_name
    @collection = @collection.joins(:attachment_type)
    table = Dorsale::Alexandrie::AttachmentType.table_name
    Arel.sql %(LOWER(#{table}.name) #{direction})
  else
    {created_at: :desc, id: :desc}
  end
end