Sha256: 971703928c1d01de93c832fb52cc908deeaf35f9e8fd2ba701f7c097db060a84

Contents?: true

Size: 712 Bytes

Versions: 8

Compression:

Stored size: 712 Bytes

Contents

module Shoppe
  class ProductCategory < ActiveRecord::Base
  
    self.table_name = 'shoppe_product_categories'
  
    # Categories have an image attachment
    attachment :image
  
    # All products within this category
    has_many :products, :dependent => :restrict_with_exception, :class_name => 'Shoppe::Product'
    
    # Validations
    validates :name, :presence => true
    validates :permalink, :presence => true, :uniqueness => true

    # All categories ordered by their name ascending
    scope :ordered, -> { order(:name) }
    
    # Set the permalink on callback
    before_validation { self.permalink = self.name.parameterize if self.permalink.blank? && self.name.is_a?(String) }
  
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
shoppe-1.0.2 app/models/shoppe/product_category.rb
shoppe-1.0.1 app/models/shoppe/product_category.rb
shoppe-1.0.0 app/models/shoppe/product_category.rb
shoppe-0.0.21 app/models/shoppe/product_category.rb
shoppe-0.0.20 app/models/shoppe/product_category.rb
shoppe-0.0.19 app/models/shoppe/product_category.rb
shoppe-0.0.18 app/models/shoppe/product_category.rb
shoppe-0.0.17 app/models/shoppe/product_category.rb