Module: SortField::ClassMethods

Defined in:
app/models/concerns/sort_field.rb

Instance Method Summary collapse

Instance Method Details

#sort_field(prefix = '') ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'app/models/concerns/sort_field.rb', line 5

def sort_field(prefix = '')
  prefix = "#{prefix}_" unless prefix == ''

  if RocketCMS.mongoid?
    field "#{prefix}sort".to_sym, type: Integer
    scope "#{prefix}sorted".to_sym, -> { asc("#{prefix}sort".to_sym) }
  end
  if RocketCMS.active_record?
    scope "#{prefix}sorted".to_sym, -> { order("#{prefix}sort".to_sym => :asc) }
  end
end