class

Marten::Routing::Map

Inherits Reference / Object

Constructors

new(namespace : String | Symbol | Nil = nil)
Source

Class methods

draw(namespace : String | Symbol | Nil = nil, &)
Source

Instance methods

draw
Source
localized(prefix_default_locale = true, &) : Nil

Allows to define routes that are localized.

When localized routes are defined, the current locale will be automatically prepended to the path of the localized routes and the routes map will be able to resolve paths in a locale-aware manner. By default, the locale prefix will be added to the path of the localized routes for all locales (including the default locale). It is however possible to customize this behavior by passing false to the prefix_default_locale argument (so that the locale prefix is not added for the default locale).

For example:

Marten::Routing::Map.draw do
  localized do
    path t("routes.blog"), Blogging::BlogHandler, name: "blog"
    path t("routes.post_detail"), Blogging::PostHandler, name: "post_detail"
  end
end
Source
path(path : String | TranslatedPath, target : Map, name : String | Symbol | Nil = nil) : Nil

Inserts a new path into the routes map.

The target associated with the considered path must be a Marten::Routing::Map instance. The <path, target> pair has an optional name that will be prepended to each <path, target> pair inside the Marten::Routing::Map.

Source
path(path : String | TranslatedPath, target : Marten::Handlers::Base.class, name : String | Symbol) : Nil

Inserts a new path into the routes map.

The target associated with the considered path must be a handler (subclass of Marten::Handlers::Base). Each <path, target> pair must be given a name that will be used to uniquely identify the route.

Source
resolve(path : String) : Match

Resolves a path - identify a route matching a specific path.

The route resolution process tries to identify which handler corresponds to the considered path and returns a Marten::Routing::Match object if a match is found. If no match is found a Marten::Routing::Errors::NoResolveMatch exception is raised.

Source
reverse(name : String | Symbol, params : Hash(String | Symbol, Parameter::Types))

Reverses a URL - returns the URL corresponding to a specific route name and hash of parameters.

The URL lookup mechanism tries to identify the route matching the given name and tries to apply the parameters defined in the parameters hash passed in the method call. If no route is found or if the arguments can't be applied to the route, a Marten::Routing::Errors::NoReverseMatch exception is raised.

Source
reverse(name : String | Symbol, **kwargs) : String

Reverses a URL - returns the URL corresponding to a specific route name and parameters.

The URL lookup mechanism tries to identify the route matching the given name and tries to apply any extra parameters passed in the method call. If no route is found or if the arguments can't be applied to the route, a Marten::Routing::Errors::NoReverseMatch exception is raised.

Source
rules
Source
t(path : String) : TranslatedPath

Returns a translated path.

path must be a valid translation key.

Source