Sha256: 9dd875922adb7258c98a0fb1258baed188332ac6cf3e6af8e556600baddaba32

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

class ContentPartLocalization < ActiveRecord::Base
  
  validates_presence_of :title, :body, :body_raw
  validates_uniqueness_of :permalink

  belongs_to :content_part
  
  # for use as a post/summary post in conjunction with the excerpt
  has_one :image, :class_name => 'ContentImage', :dependent => :destroy, :as => :content_part
  has_one :image_overlay, :foreign_key => "content_part_as_overlay_id", :class_name => 'ContentImage', :dependent => :destroy, :as => :content_part_as_overlay_image
    
  before_validation :process_body, :create_permalink
  
  protected
  
  def create_permalink
    # do not update permalinks automatically. Ever.
    return unless self.permalink.blank?
    
    self.permalink = self.title.parameterize
      
    if self.permalink.blank?
      self.permalink = Digest::SHA1.hexdigest("fubar-#{Time.now.to_s}")
    end
  end
  
  def process_body
    self.body = self.body_raw
  end
  
  def image_path=(image)
    self.build_image :image => image
  end
  
  def image_path
    if self.image && self.image.image
      self.image.image.url
    else
      ""
    end
  end
  
  def image_overlay_path=(image)
    self.build_image_overlay :image => image
  end
  
  def image_overlay_path
    if self.image_overlay && self.image_overlay.image
      self.image_overlay.image.url
    else
      ""
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree-cms-0.2.1 app/models/content_part_localization.rb
spree-cms-0.2.0 app/models/content_part_localization.rb