Files
writebook/app/models/leaf.rb

16 lines
423 B
Ruby

class Leaf < ApplicationRecord
include Editable, Positionable
belongs_to :book, touch: true
delegated_type :leafable, types: Leafable::TYPES, dependent: :destroy
positioned_within :book, association: :leaves, filter: :active
enum :status, %w[ active trashed ].index_by(&:itself), default: :active
scope :with_leafables, -> { includes(:leafable) }
def slug
title.parameterize.presence || "-"
end
end