Sha256: 459257faca15bb5a33f1d90232644a29980fd274c14cdca619e82d68298774af
Contents?: true
Size: 1 KB
Versions: 1
Compression:
Stored size: 1 KB
Contents
module EtabliocmsPages class Page < ActiveRecord::Base acts_as_nested_set attr_accessor :child_of after_save :update_position validates :title, :presence => true validates :locale, :presence => true has_slug :to_param => "path" def path self_and_ancestors.map(&:slug).join("/") end def other_pages_for_select pages = EtabliocmsPages::Page.order("lft ASC") pages = pages.where("id != ?", id) unless new_record? pages.map { |d| [d.title, d.id] } end scope :for_locale, lambda { |locale| where(:locale => locale) } scope :visible, where(:visible => true) private def update_position if child_of.to_i != parent_id.to_i if child_of.present? parent = Page.find(child_of) move_to_child_of parent unless parent == self or parent == self.parent move_to_bottom elsif !child_of.nil? move_to_root move_to_bottom end end self.child_of = nil end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
etabliocms_pages-0.0.1 | app/models/etabliocms_pages/page.rb |