Class: Category
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Category
- Defined in:
- app/models/category.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.columns_for_index ⇒ Object
36 37 38 39 40 |
# File 'app/models/category.rb', line 36 def self.columns_for_index [ {:label => I18n.t("models.category.name_label"), :method => :name, :order => "categories.name" }, {:label => I18n.t("models.category.type_label"), :method => :category_type_name, :order => "category_types.name" }, {:label => I18n.t("models.category.updated_label"), :method => :updated_on_string, :order => "categories.updated_at"} ] end |
.display_name ⇒ Object
42 43 44 |
# File 'app/models/category.rb', line 42 def self.display_name I18n.t("models.category.display_name") end |
.display_name_plural ⇒ Object
46 47 48 |
# File 'app/models/category.rb', line 46 def self.display_name_plural I18n.t("models.category.display_name_plural") end |
Instance Method Details
#ancestors ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/category.rb', line 16 def ancestors fn = lambda do |cat, parents| if cat.parent_id p = self.class.find(cat.parent) fn.call(p, (parents << p)) else parents.reverse end end fn.call(self, []) end |
#category_type_name ⇒ Object
32 33 34 |
# File 'app/models/category.rb', line 32 def category_type_name category_type ? category_type.name : nil end |
#path(sep = " > ") ⇒ Object
28 29 30 |
# File 'app/models/category.rb', line 28 def path(sep=" > ") (ancestors.map(&:name) + [name]).join(sep) end |