Skip to content

Trek::Sectionable

Organizes a record's content into ordered, typed sections (hero, features, testimonials…).

What it adds

  • has_many :sections, -> { ordered }, as: :sectionable, dependent: :destroy
  • sections_instances — the unwrapped section objects, in order

Usage

ruby
class Page < ApplicationRecord
  include Trek::Sectionable

  SECTIONS = [HeroSection, FeaturesSection].freeze
end

page.sections_instances.each do |section|
  render section_component_for(section)
end

Sections are opt-in per page via the sectioned boolean column. The including class defines the allowed section types through the SECTIONS constant.

Released under the MIT License.