Sha256: b617230ab3f77a2fbf077d86306f1db254b73c89c87aed229e50a3ef133f6409
Contents?: true
Size: 1.07 KB
Versions: 7
Compression:
Stored size: 1.07 KB
Contents
module Spina class PagePart < ActiveRecord::Base include ApplicationHelper belongs_to :page belongs_to :page_partable, polymorphic: true accepts_nested_attributes_for :page_partable, allow_destroy: true attr_accessor :position validates_presence_of :name, :page_partable_type, :title validates_uniqueness_of :name, scope: :page_id scope :sorted, -> { order(:position) } alias_attribute :partable, :page_partable def to_s name end def position(theme) page_parts = theme.config.view_templates[self.page.try(:view_template) || "show"][:page_parts] page_parts.index { |page_part| page_part == self.name }.to_i end def content self.page_partable.try(:content) || self.page_partable end def page_partable_attributes=(attributes) if self.page_partable.present? self.page_partable.assign_attributes(attributes) else self.page_partable = self.page_partable_type.constantize.new(attributes) end end def partable_type page_partable_type end end end
Version data entries
7 entries across 7 versions & 1 rubygems