---
url: /reference/concerns/versionable.md
---
# Trek::Pages::Versionable

Content versioning for [pages](/reference/models/page): snapshot the current content and image as a [PageVersion](/reference/models/page-version), then keep editing while the snapshot stays live.

## What it adds

* `has_many :versions` (most recent first), plus `accepts_nested_attributes_for :versions`; `page.versions.current` returns the current version, a record (or `nil`)

## 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
```
