Skip to content

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_path and has_many :pathsPagePath
  • after_save_commit, paths are (re)created for the page and all its descendants

Methods

MethodReturns
Page.find_at_full_path(path)the page at this path (raises ActiveRecord::RecordNotFound)
full_paththe current path string
full_path_from_treethe 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") # => child

Old paths remain in page.paths, which lets your front-end controllers redirect outdated URLs to full_path.

Released under the MIT License.