Class: Shoppy::Category

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/shoppy/category.rb

Direct Known Subclasses

Category

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_sortedObject



32
33
34
# File 'app/models/shoppy/category.rb', line 32

def self.all_sorted
  self.all.sort_by {|c| c.breadcrumb }
end

Instance Method Details



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/shoppy/category.rb', line 18

def breadcrumb
  bc = [self.id]
  fbc = "Root -> "
  c = self
  while c.parent_category
    bc.append(c.parent_category.id)
    c = c.parent_category
  end
  bc.reverse.each do |c|
    fbc += (Category.find(c).name + " -> ")
  end
  fbc[0..(fbc.length - 5)]
end

#nameObject

Validators



12
# File 'app/models/shoppy/category.rb', line 12

validates :name, presence: true

#parent_categoryObject

Relationships



4
# File 'app/models/shoppy/category.rb', line 4

belongs_to  :parent_category, class_name: "Category"