Trek::Pages::Versionable
Content versioning for pages: snapshot the current content and image as a PageVersion, then keep editing while the snapshot stays live.
What it adds
has_many :versions(most recent first) with acurrentsub-scope, plusaccepts_nested_attributes_for :versions
Methods
| Method | Purpose |
|---|---|
create_current_version_from_page! | snapshots the page's content and image as the new current version |
current_version | the live version (or nil when not versioned) |
current_content / current_sections | content from the current version, falling back to the page itself |
current_image / current_image_url | image from the current version, falling back to the page, then its parent |
Usage
Versioning is opt-in per page via the versioned boolean column:
ruby
page.update(versioned: true)
page.create_current_version_from_page! # freeze what's live
page.update(content: new_draft) # keep editing safely
page.current_content # => still the frozen snapshot