Sha256: a5f3fb52f9f6eafb9a2d0943f6b528006ae9c39d48f2b45b40c1485febae2e14
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
class Spree::Page < ActiveRecord::Base default_scope :order => "position ASC" validates_presence_of :title validates_presence_of [:slug, :body], :if => :not_using_foreign_link? scope :visible, where(:visible => true) scope :header_links, where(:show_in_header => true).visible scope :footer_links, where(:show_in_footer => true).visible scope :sidebar_links, where(:show_in_sidebar => true).visible before_save :update_positions_and_slug def initialize(*args) super(*args) last_page = Spree::Page.last self.position = last_page ? last_page.position + 1 : 0 end def link foreign_link.blank? ? slug_link : foreign_link end private def update_positions_and_slug unless new_record? return unless prev_position = Spree::Page.find(self.id).position if prev_position > self.position Spree::Page.update_all("position = position + 1", ["? <= position AND position < ?", self.position, prev_position]) elsif prev_position < self.position Spree::Page.update_all("position = position - 1", ["? < position AND position <= ?", prev_position, self.position]) end end if not_using_foreign_link? self.slug = slug_link Rails.cache.delete('page_not_exist/' + self.slug) end return true end def not_using_foreign_link? foreign_link.blank? end def slug_link ensure_slash_prefix slug end def ensure_slash_prefix(str) str.index('/') == 0 ? str : '/' + str end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
spree_static_content-1.0.1 | app/models/spree/page.rb |