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
16 17 18 |
# File 'app/models/caboose/block_type_category.rb', line 16 def self.content self.where("name = ? and parent_id is null", 'Content').reorder(:name).all end |
.layouts ⇒ Object
12 13 14 |
# File 'app/models/caboose/block_type_category.rb', line 12 def self.layouts self.where("name = ? and parent_id is null", 'Layouts').reorder(:name).all end |
.rows ⇒ Object
20 21 22 23 24 |
# File 'app/models/caboose/block_type_category.rb', line 20 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
26 27 28 29 30 31 32 |
# File 'app/models/caboose/block_type_category.rb', line 26 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
34 35 36 37 38 39 |
# File 'app/models/caboose/block_type_category.rb', line 34 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 |