summaryrefslogtreecommitdiff
path: root/app/models/node.rb
blob: 6e540047a0cf980d77ed4797dc5066e35cbf145b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Node < ActiveRecord::Base
  acts_as_nested_set
  
  has_many :pages, :order => "revision ASC"
  
  # returns array with pages up to root excluding root
  def path_to_root
    parent.nil? && [slug] || parent.path_to_root.push(slug)
  end
  
  def update_unique_name
    path = self.path_to_root[1..-1]
    self.unique_name = path.join("/")
  end
end