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_paramsto sort for the givenattr_namesfor 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 |
# File 'lib/zable/sort.rb', line 7 def inherited(subclass) subclass.class_eval do scope :for_sort_params, -> sort_params { inject_sort_scope(sort_params) } 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
18 19 20 21 22 |
# File 'lib/zable/sort.rb', line 18 def sortable(*attr_names) attr_names.each do |attr_name| scope "sort_#{attr_name}", -> { order("#{table_name}.#{attr_name} #{options[:order]}") } end end |