Trek::Fragmentable
Composes a record from reusable fragments, based on a configuration matrix mapping record keys to fragment ids.
Configuration
yaml
# page_fragments configuration
page_fragments:
matrix:
home: [1, 2, 3]
about: [4, 5]Methods
| Method | Purpose |
|---|---|
fragments | the Fragment records configured for this record's key |
fragments_attributes= | bulk-updates fragments from nested form attributes |
Usage
ruby
class Page < ApplicationRecord
include Trek::Fragmentable
end
page = Page.find_by(key: "home")
page.fragments # => [Fragment(1), Fragment(2), Fragment(3)]This is what powers the fragment editing UI on page forms in the admin.