Sha256: e0e57ea9bfc7fca8af3705611b3a09e34ecfe8e12ff1761c5f90a3c891629402

Contents?: true

Size: 1.29 KB

Versions: 13

Compression:

Stored size: 1.29 KB

Contents

class Page < ActiveRecord::Base
  
  has_paper_trail
  has_friendly_id :title, :use_slug => true
  
  acts_as_indexed :fields => [:title, :body, :area_1, :area_2, :meta_keywords, :meta_description, :nav_label]  
  
  acts_as_tree :order => "position"
  
  has_many :menu_items, :as => :menuable, :dependent => :destroy
  has_many :galleries, :as => :galleriable
  
  default_scope order("parent_id, position")
  scope :published, where("publish = ? OR (release_at > ? AND expire_at < ?) ", true, Time.zone.now, Time.zone.now)
  before_save :set_nav_label
  
  include Soapbox::Page if File.exists? "app/models/soapbox/page.rb"
  
  def self.homepage
    self.where("homepage=?",true).first
  end
  
  def title_bread_crumb
    title = self.title
    page = self
    i = 0
    until page.parent.nil? || page.parent_id == page.id  || i > 10
      i += 1
      page = page.parent
      title += " &raquo; #{page.title}".html_safe
    end
    title.html_safe
  end
  
  def parents
    parents = [self]
    page = self
    i = 0
    until page.nil? || page.parent_id == page.id  || i > 10
      i += 1
      page = page.parent
      parents << page unless page.nil?
    end
    parents.reverse!
  end
  
private
  def set_nav_label
    self.nav_label = self.title if self.nav_label.nil? || self.nav_label.empty?
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
soapbox-0.3.1 app/models/page.rb
soapbox-0.3.0 app/models/page.rb
soapbox-0.2.24 app/models/page.rb
soapbox-0.2.23 app/models/page.rb
soapbox-0.2.21 app/models/page.rb
soapbox-0.2.20 app/models/page.rb
soapbox-0.2.18 app/models/page.rb
soapbox-0.2.16 app/models/page.rb
soapbox-0.2.15 app/models/page.rb
soapbox-0.2.14 app/models/page.rb
soapbox-0.2.12 app/models/page.rb
soapbox-0.2.11 app/models/page.rb
soapbox-0.2.10 app/models/page.rb