Sha256: ead9814babb7ef3621589bc32d98b54f34b7a4907360df06e1a3a60b43cb0f3e
Contents?: true
Size: 1.07 KB
Versions: 7
Compression:
Stored size: 1.07 KB
Contents
module Spina class LayoutPart < ActiveRecord::Base include ApplicationHelper belongs_to :account belongs_to :layout_partable, polymorphic: true accepts_nested_attributes_for :layout_partable, allow_destroy: true attr_accessor :position validates_presence_of :name, :layout_partable_type, :title validates_uniqueness_of :name, scope: :account_id scope :sorted, -> { order(:position) } alias_attribute :partable, :layout_partable def to_s name end def position(theme) layout_parts = theme.config.layout_template[:layout_parts] layout_parts.index { |layout_part| layout_part == self.name }.to_i end def content self.layout_partable.try(:content) || self.layout_partable end def layout_partable_attributes=(attributes) if self.layout_partable.present? self.layout_partable.update_attributes(attributes) else self.layout_partable = self.layout_partable_type.constantize.create(attributes) end end def partable_type layout_partable_type end end end
Version data entries
7 entries across 7 versions & 1 rubygems