Sha256: 36ac642df6a1f3a7e3260a6cf0af1f679f0c9cac8999953fc100d0d40c7b4676
Contents?: true
Size: 1.64 KB
Versions: 1
Compression:
Stored size: 1.64 KB
Contents
class Index < ActiveRecord::Base attr_accessible :name, :title, :page_title, :keywords, :page_description, :texts_attributes, :photos_attributes, :videos_attributes, :downloadables_attributes, :gallery_attributes delegate :asset, :to => :"photos.first", :allow_nil => true alias_method :photo, :asset before_validation :default_name extend FriendlyId friendly_id :name, :use => :slugged include ActsAsPrioritizable acts_as_prioritizable("owner", "indices") default_scope :order => 'priority ASC' after_initialize do self.priority ||= lowest_priority + 1 end has_many :indices, :as => :owner, :dependent => :destroy belongs_to :owner, :polymorphic => true has_one :gallery, :dependent => :destroy has_many :texts, :dependent => :destroy has_many :photos, :dependent => :destroy has_many :videos, :dependent => :destroy has_many :downloadables, :dependent => :destroy accepts_nested_attributes_for :videos, :reject_if => lambda { |a| a[:remote_id].blank? }, :allow_destroy => true accepts_nested_attributes_for :photos, :reject_if => lambda { |a| a[:asset].blank? }, :allow_destroy => true accepts_nested_attributes_for :downloadables, :reject_if => lambda { |a| a[:asset].blank? }, :allow_destroy => true accepts_nested_attributes_for :texts, :reject_if => lambda { |a| a[:content].blank?}, :allow_destroy => true accepts_nested_attributes_for :gallery, :allow_destroy => true def assets (texts + photos + videos + downloadables).sort_by{|a| a.priority || 99} end def default_name self.name ||= (self.title ||= self.owner.name).tableize rescue nil self.title ||= self.name.titleize rescue nil end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sbdevcore-0.2.11 | app/models/index.rb |