Sha256: b497c248c79bef2fe144770570e266bf29a78b564c843f981a978f9e68fc8dff
Contents?: true
Size: 1.06 KB
Versions: 7
Compression:
Stored size: 1.06 KB
Contents
module PageflowScrolled class Chapter < Pageflow::ApplicationRecord include Pageflow::SerializedConfiguration include Pageflow::AutoGeneratedPermaId include Pageflow::NestedRevisionComponent belongs_to :storyline, touch: true has_many :sections, -> { order('pageflow_scrolled_sections.position ASC') }, dependent: :destroy, inverse_of: :chapter has_many :content_elements, through: :sections nested_revision_components :sections attr_accessor :revision # used on :create to lazily create storyline before_validation :ensure_storyline, on: :create def self.all_for_revision(revision) joins(storyline: :revision) .where(pageflow_scrolled_storylines: {revision_id: revision}) end private def ensure_storyline return if storyline.present? unless Storyline.all_for_revision(revision).exists? Storyline.create!(revision: revision, configuration: {main: true}) end self.storyline = Storyline.all_for_revision(revision).first end end end
Version data entries
7 entries across 7 versions & 1 rubygems