Class: Caboose::BlockTypeCategory
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Caboose::BlockTypeCategory
- Defined in:
- app/models/caboose/block_type_category.rb
Class Method Summary collapse
- .content ⇒ Object
- .layouts ⇒ Object
- .rows ⇒ Object
- .tree ⇒ Object
- .tree_helper(arr, cat, prefix) ⇒ Object
Class Method Details
.content ⇒ Object
18 19 20 |
# File 'app/models/caboose/block_type_category.rb', line 18 def self.content self.where("name = ? and parent_id is null", 'Content').reorder(:name).all end |
.layouts ⇒ Object
14 15 16 |
# File 'app/models/caboose/block_type_category.rb', line 14 def self.layouts self.where("name = ? and parent_id is null", 'Layouts').reorder(:name).all end |
.rows ⇒ Object
22 23 24 25 26 |
# File 'app/models/caboose/block_type_category.rb', line 22 def self.rows cat = self.content return false if cat.nil? self.where("name = ? and parent_id = ?", 'Rows', cat.id).reorder(:name).all end |
.tree ⇒ Object
28 29 30 31 32 33 34 |
# File 'app/models/caboose/block_type_category.rb', line 28 def self.tree arr = [] self.where("parent_id is null").reorder(:name).all.each do |cat| self.tree_helper(arr, cat, '') end return arr end |
.tree_helper(arr, cat, prefix) ⇒ Object
36 37 38 39 40 41 |
# File 'app/models/caboose/block_type_category.rb', line 36 def self.tree_helper(arr, cat, prefix) arr << { 'value' => cat.id, 'text' => "#{prefix}#{cat.name}" } cat.children.each do |kid| self.tree_helper(arr, kid, "#{prefix} - ") end end |