app/models/spina/page_part.rb in spina-0.8.3 vs app/models/spina/page_part.rb in spina-0.9.0
- old
+ new
@@ -1,44 +1,20 @@
module Spina
class PagePart < ActiveRecord::Base
- include ApplicationHelper
+ include Part
- belongs_to :page
+ belongs_to :page, inverse_of: :page_parts
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
+ validates :name, uniqueness: {scope: :page_id}
- scope :sorted, -> { order(:position) }
-
alias_attribute :partable, :page_partable
+ alias_attribute :partable_type, :page_partable_type
+ alias_method :page_partable_attributes=, :partable_attributes=
- 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
+ page.view_template_config(theme)[: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