Trek::Pages::Pathable
Manages a page's URL paths across locales: the current path, the full history (for redirects), and automatic regeneration when pages move in the tree.
What it adds
belongs_to :current_pathandhas_many :paths→ PagePathafter_save_commit, paths are (re)created for the page and all its descendants
Methods
| Method | Returns |
|---|---|
Page.find_at_full_path(path) | the page at this path (raises ActiveRecord::RecordNotFound) |
full_path | the current path string |
full_path_from_tree | the path computed from ancestor slugs |
Usage
ruby
parent = Page.create(title: "Services")
child = Page.create(title: "Design", parent: parent)
child.full_path # => "services/design"
Page.find_at_full_path("services/design") # => childOld paths remain in page.paths, which lets your front-end controllers redirect outdated URLs to full_path.