Sha256: 8b8258f94e27197eb381c579e661185da0a7c21a28b62e030cb55a1187d64a0e

Contents?: true

Size: 858 Bytes

Versions: 3

Compression:

Stored size: 858 Bytes

Contents

class Kuhsaft::LocalizedPage < ActiveRecord::Base
  belongs_to :page
  has_many :page_parts, :class_name => 'Kuhsaft::PagePart::Content'
  before_validation :create_slug
  before_validation :create_url
  
  delegate :childs, :to => :page
  
  validates :title, :presence => true
  validates :locale, :presence => true
  validates :slug, :presence => true
  
  def locale
    read_attribute(:locale).to_sym unless read_attribute(:locale).nil?
  end
  
  def create_url
    complete_slug = ''
    if page.present? && page.parent.present?
      complete_slug << page.parent.url.to_s
    else
      complete_slug = "#{self.locale}"
    end
    complete_slug << "/#{self.slug}"
    self.url = complete_slug
  end
  
  def create_slug
    if title.present? && slug.blank?
      write_attribute(:slug, read_attribute(:title).downcase.parameterize)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kuhsaft-0.0.6 app/models/kuhsaft/localized_page.rb
kuhsaft-0.0.5 app/models/kuhsaft/localized_page.rb
kuhsaft-0.0.4 app/models/kuhsaft/localized_page.rb