app/models/spina/structure_item.rb in spina-0.11.1 vs app/models/spina/structure_item.rb in spina-0.12.0
- old
+ new
@@ -1,22 +1,18 @@
module Spina
class StructureItem < ApplicationRecord
+ include Partable
+
before_validation :ensure_position
belongs_to :structure, optional: true
has_many :structure_parts, dependent: :destroy
- scope :sorted_by_structure, -> { order('position') }
+ scope :sorted_by_structure, -> { order(:position) }
validates_presence_of :position
accepts_nested_attributes_for :structure_parts, allow_destroy: true
- def has_content?(structure_part)
- content(structure_part).present?
- end
-
- def content(structure_part)
- structure_parts.find_by(name: structure_part).try(:content)
- end
+ alias_attribute :parts, :structure_parts
def ensure_position
self.position ||= Time.now.to_i
end
end