Class: Toller::Sorts::ColumnHandler
- Inherits:
-
Object
- Object
- Toller::Sorts::ColumnHandler
- Defined in:
- lib/toller/sorts/column_handler.rb
Overview
Column handler for filter
Instance Method Summary collapse
-
#call(collection, direction, properties) ⇒ ActiveRecord::Relation
Applies a plain
orderclause tocollectionfor a non-scope sort.
Instance Method Details
#call(collection, direction, properties) ⇒ ActiveRecord::Relation
Applies a plain order clause to collection for a non-scope sort.
If field isn't a real column on the collection's model, the sort is
logged and skipped instead of raising once the relation is evaluated.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/toller/sorts/column_handler.rb', line 19 def call(collection, direction, properties) field_name = properties[:field] unless collection.klass.column_names.include?(field_name.to_s) Rails.logger.warn("[Toller] Skipping sort: #{collection.klass} has no column `#{field_name}`") return collection end collection.order(field_name => direction) end |