Class: Shoppy::Category
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Shoppy::Category
- Defined in:
- app/models/shoppy/category.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #breadcrumb ⇒ Object
-
#name ⇒ Object
Validators.
-
#parent_category ⇒ Object
Relationships.
Class Method Details
.all_sorted ⇒ Object
32 33 34 |
# File 'app/models/shoppy/category.rb', line 32 def self.all_sorted self.all.sort_by {|c| c. } end |
Instance Method Details
#breadcrumb ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/shoppy/category.rb', line 18 def 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 |
#name ⇒ Object
Validators
12 |
# File 'app/models/shoppy/category.rb', line 12 validates :name, presence: true |
#parent_category ⇒ Object
Relationships
4 |
# File 'app/models/shoppy/category.rb', line 4 belongs_to :parent_category, class_name: "Category" |