Sha256: d6b8088ac378930e4adb52e559cf05d00124b077fb9954b677d022b333f873c4
Contents?: true
Size: 815 Bytes
Versions: 3
Compression:
Stored size: 815 Bytes
Contents
class Category < ActiveRecord::Base acts_as_nested_set has_permalink :title, :scope => :section_id belongs_to :section, :foreign_key => 'section_id' has_many :contents, :through => :category_assignments has_many :category_assignments, :dependent => :delete_all before_validation :set_path validates_presence_of :section, :title validates_uniqueness_of :permalink, :scope => :section_id def set_path new_path = build_path unless self.path == new_path self.path = new_path @paths_dirty = true end end def update_child_paths return unless @paths_dirty self.all_children.each do |child| child.path = child.build_path child.save end @paths_dirty = false end def build_path self_and_ancestors.map(&:permalink).join('/') end end
Version data entries
3 entries across 3 versions & 1 rubygems