Sha256: 3d63f3194cf595b2ff1ce2e519a88b8c12eea048725e9c704adb1787c61d4baa

Contents?: true

Size: 888 Bytes

Versions: 11

Compression:

Stored size: 888 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

  # open up everything for mass assignment
  attr_protected

  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

11 entries across 11 versions & 1 rubygems

Version Path
forge-cli-0.1.10 lib/forge/app/models/product_category.rb
forge-cli-0.1.9 lib/forge/app/models/product_category.rb
forge-cli-0.1.8 lib/forge/app/models/product_category.rb
forge-cli-0.1.7 lib/forge/app/models/product_category.rb
forge-cli-0.1.6 lib/forge/app/models/product_category.rb
forge-cli-0.1.5 lib/forge/app/models/product_category.rb
forge-cli-0.1.4 lib/forge/app/models/product_category.rb
forge-cli-0.1.3 lib/forge/app/models/product_category.rb
forge-cli-0.1.2 lib/forge/app/models/product_category.rb
forge-cli-0.1.1 lib/forge/app/models/product_category.rb
forge-cli-0.1.0 lib/forge/app/models/product_category.rb