Class: Formol::Category

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
RankedModel
Defined in:
app/models/formol/category.rb

Class Method Summary collapse

Class Method Details

.ready_for_listingObject

return categories conveniently ordered and eager-loaded for listing



26
27
28
# File 'app/models/formol/category.rb', line 26

def ready_for_listing
  includes(:forums => { :last_post => [:user, :topic] }).rank(:position)
end

.sort(category_ids) ⇒ Object

Sorts categories from an array of ids



34
35
36
37
38
39
# File 'app/models/formol/category.rb', line 34

def sort(category_ids)
  #TODO: should maybe optimize this?
  (category_ids || []).each_with_index do |category_id, index|
    find(category_id).update_attribute(:position, index)
  end
end