Class: Kms::Category

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Includes:
CompileTemplates, Permalinkable, Liquor::Dropable
Defined in:
app/models/kms/category.rb

Instance Method Summary collapse

Instance Method Details

#set_positionObject



14
15
16
17
18
19
20
21
# File 'app/models/kms/category.rb', line 14

def set_position
  if parent.present?
    max = parent.children.maximum(:position)
  else
    max = Category.where('ancestry IS ?', nil).maximum(:position)
  end
  self.position = max ? max + 1 : 0
end