Module: Zable::Sort::ActiveRecord::ClassMethods
- Defined in:
- lib/zable/sort.rb
Instance Method Summary collapse
- #inherited(subclass) ⇒ Object
-
#sortable(*attr_names) ⇒ Object
Allows
Model.for_sort_params
to sort for the givenattr_names
for the common sorting case (i.e. “attr_name ASC” or “attr_name DESC”).
Instance Method Details
#inherited(subclass) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/zable/sort.rb', line 7 def inherited(subclass) subclass.class_eval do def self.for_sort_params(sort_params) return self unless sort_params inject_sort_scope(sort_params) end end super(subclass) end |
#sortable(*attr_names) ⇒ Object
Allows Model.for_sort_params
to sort for the given attr_names
for the common sorting case (i.e. “attr_name ASC” or “attr_name DESC”)
sortable :last_name, :created_at
21 22 23 24 25 |
# File 'lib/zable/sort.rb', line 21 def sortable(*attr_names) attr_names.each do |attr_name| scope "sort_#{attr_name}", -> ordering { order("#{table_name}.#{attr_name} #{ordering}") } end end |