Sha256: a12ee819a493420d22d752264a20b898c48018d2ad1b5e3eba9619b3067aadd4
Contents?: true
Size: 826 Bytes
Versions: 13
Compression:
Stored size: 826 Bytes
Contents
class ProductCategory < ActiveRecord::Base include Forge::Reorderable default_scope :order => 'product_categories.list_order' before_destroy :validate_destroy has_many :products belongs_to :sale belongs_to :parent, :class_name => "ProductCategory", :foreign_key => "parent_id" has_many :subcategories, :class_name => "ProductCategory", :foreign_key => "parent_id", :dependent => :destroy, :order => "list_order" validates_presence_of :title def validate_destroy products.count < 1 end def parents( category=self ) #Probably need to modify this to use slug instead of title? At least parameterize things. if category.parent.nil? return [category.title] else return parents(category.parent).concat([category.title]) end end def path parents.join('/') end end
Version data entries
13 entries across 13 versions & 1 rubygems