Class: Cms::CategoryType
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cms::CategoryType
- Defined in:
- app/models/cms/category_type.rb
Class Method Summary collapse
-
.category_map ⇒ Object
Return a map when the key is category type id as a string and the value is an array of arrays, each entry having the first value as the category path and the second value being the category id as a string.
Instance Method Summary collapse
- #cannot_be_deleted_message ⇒ Object
-
#category_list(order = "name") ⇒ Object
This is used to get the full list of categories for this category type in the correct order.
Class Method Details
.category_map ⇒ Object
Return a map when the key is category type id as a string and the value is an array of arrays, each entry having the first value as the category path and the second value being the category id as a string
16 17 18 19 20 21 |
# File 'app/models/cms/category_type.rb', line 16 def self.category_map all.inject(Hash.new([])) do |map, ct| map[ct.id.to_s] = ct.category_list.map { |c| [c.path, c.id.to_s] } map end end |
Instance Method Details
#cannot_be_deleted_message ⇒ Object
34 35 36 |
# File 'app/models/cms/category_type.rb', line 34 def categories.count.zero? ? nil : "This cannot be deleted because it is in use in #{categories.count} #{"category".pluralize_unless_one(categories.count)}" end |
#category_list(order = "name") ⇒ Object
This is used to get the full list of categories for this category type in the correct order.
24 25 26 27 28 29 30 31 32 |
# File 'app/models/cms/category_type.rb', line 24 def category_list(order="name") list = [] fn = lambda do |cat| list << cat cat.children.all(:order => order).each { |c| fn.call(c) } end categories.top_level.all(:order => order).each { |cat| fn.call(cat) } list end |