Class: Content

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/content.rb

Defined Under Namespace

Classes: Resource, Seo

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_ancestry(ancestry = nil, id) ⇒ Object



36
37
38
39
40
41
42
43
# File 'app/models/content.rb', line 36

def self.find_by_ancestry(ancestry = nil, id)
  return self.find(id) unless ancestry
  parent = Content.find(ancestry.shift)
  while(parent_slug = ancestry.shift and parent_slug != id) do
    parent = parent.child_contents.find(parent_slug)
  end if parent
  parent.child_contents.find(id)
end

Instance Method Details

#ancestryObject



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

def ancestry
  parent_content ? parent_content.ancestry << id : [id]
end

#child_orderObject



48
# File 'app/models/content.rb', line 48

def child_order; end

#child_order=(order) ⇒ Object



45
46
47
# File 'app/models/content.rb', line 45

def child_order=(order)
  @child_order = order
end

#to_paramObject



50
51
52
# File 'app/models/content.rb', line 50

def to_param
  parent_content ? parent_content.to_param + '/' + id : id
end