Module: TbCore::SortableParams::ClassMethods

Defined in:
app/controllers/concerns/tb_core/sortable_params.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_sort_attributeObject

Returns the value of attribute default_sort_attribute.



6
7
8
# File 'app/controllers/concerns/tb_core/sortable_params.rb', line 6

def default_sort_attribute
  @default_sort_attribute
end

#sortable_mappingObject

Returns the value of attribute sortable_mapping.



7
8
9
# File 'app/controllers/concerns/tb_core/sortable_params.rb', line 7

def sortable_mapping
  @sortable_mapping
end

Instance Method Details

#sortable_by(*attributes, **options) ⇒ Object

Define attributes you wish to sort by

This optional configuration method tells the the sortable helpers how they should map attributes to queries. For example a “name” sort might need to sort on first and last name attributes

The ‘default` argument, if passed, will determine the attribute used when no sort param has been passed

Usage:

sortable_by :email, name: [:last_name, :first_name]

default: :email,


25
26
27
28
# File 'app/controllers/concerns/tb_core/sortable_params.rb', line 25

def sortable_by(*attributes, **options)
  @default_sort_attribute = options.delete(:default)
  @sortable_mapping = options.merge(attributes.map { |att| [att, att] }.to_h)
end