Class: Category

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.columns_for_indexObject



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

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

Instance Method Details

#ancestorsObject



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_nameObject



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