Class: Cms::Category

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
DefaultAccessible
Defined in:
app/models/cms/category.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.columns_for_indexObject


40
41
42
43
44
# File 'app/models/cms/category.rb', line 40

def self.columns_for_index
  [{:label => "Name", :method => :name, :order => "#{Category.table_name}.name"},
   {:label => "Type", :method => :category_type_name, :order => "#{CategoryType.table_name}.name"},
   {:label => "Updated On", :method => :updated_on_string, :order => "#{Category.table_name}.updated_at"}]
end

Instance Method Details

#ancestorsObject


20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/cms/category.rb', line 20

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_nameObject


36
37
38
# File 'app/models/cms/category.rb', line 36

def category_type_name
  category_type ? category_type.name : nil
end

#path(sep = " > ") ⇒ Object


32
33
34
# File 'app/models/cms/category.rb', line 32

def path(sep=" > ")
  (ancestors.map(&:name) + [name]).join(sep)
end