Sha256: b08071d298a94bcac7f0142b5505984f66f30c1421df4498f4112061d7b1507c

Contents?: true

Size: 582 Bytes

Versions: 2

Compression:

Stored size: 582 Bytes

Contents

module Kms
  class Category < ActiveRecord::Base
    include Liquor::Dropable
    extend FriendlyId
    include Kms::Permalinkable
    include Kms::CompileTemplates
    has_and_belongs_to_many :products
    has_ancestry
    friendly_id :name, use: :slugged
    before_create :set_position

    mount_uploader :logo, CategoryLogoUploader

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kms_catalog-0.5.0 app/models/kms/category.rb
kms_catalog-0.4.0 app/models/kms/category.rb