Skip to content

Trek::Sluggable

Auto-generates locale-aware URL slugs before validation, for every available locale.

Behavior

  • before_validation, the slug is regenerated per locale: from a route translation of the page key when one exists, otherwise by parameterizing the SEO title
  • Validates slug presence (except for the root page) and uniqueness among siblings (scope: :parent_id)

Requirements

Usage

ruby
page = Page.new(key: "services", title: "Our Services")
page.save
page.slug # => "our-services"

Released under the MIT License.