A navigable has a
slug attribute, which is a unique, human- and URL-friendly string used to identify the model, particularly when requesting the model via a URL.
For example, in the Storefront, the path /pages/foo is routed to
Storefront::PagesController#show, which looks up the requested page by slug:
to_param on a navigable returns the navigable's slug, allowing idiomatic use of Rail's routing helpers, while maintaining "pretty" URLs.
= page_path(@page) / evaluates to "/pages/foo"
A navigable must have a slug, but one will be generated if not provided explicitly. A generated slug is derived from the navigable's name, including an incrementing suffix if needed to ensure uniqueness.
Workarea::Catalog::Category.create!(name: 'Foo').slug # => "foo" Workarea::Catalog::Category.create!(name: 'Foo').slug # => "foo-1"
A navigable has a 1:1 relationship with a taxon, which represents the navigable's position within the site's taxonomy tree.
navigable = Workarea::Catalog::Product.create!(name: 'Foo') taxon = Workarea::Navigation::Taxon.create!(navigable: navigable) navigable.taxon.class # => Workarea::Navigation::Taxon navigable.taxon.name # => "Foo"
How'd We Do?
Was this article missing something?
Was it not quite what you were looking for?
Do you have suggestions on how we could improve this article or your experience in general?
If so, please take a moment to let us know!
Your invaluable feedback will help everyone better understand the platform!