module

CRails::Routes::UrlHelpers

Named route helpers (*_path / *_url) — the Rails url_helpers analogue. Routes are drawn at RUNTIME (config/routes.cr runs as plain code after the controllers are compiled), so a compile-time table is not an option; instead each call to a missing *_path/ *_url method expands — via macro method_missing, the pattern already used by action_view_cr's TagBuilder — into a method that resolves the name against the route set at runtime and builds the path. method_missing only fires when no explicit method exists: hand-written helpers in the app keep shadowing generated ones.

Semantics (minimal Rails parity, see README "Named route helpers"):

  • positional args fill dynamic segments left-to-right; objects responding to to_param are converted (room_path(room));
  • extra positional args go to the query string (key = value);
  • named opts become query params, anchor: becomes the fragment;
  • *_url = origin + *_path; origin is the request's origin method when the including context has one (controllers), then jb_origin (Jbuilder partials), then default_url_origin.

Class methods

__to_param(arg) : String

Rails to_param semantics: objects may customize their URL representation; everything else goes through to_s.

Source
default_url_origin

Fallback origin for *_url outside a request context (jobs, Jbuilder partials) — the default_url_options host analogue.

Source
default_url_origin=(default_url_origin : String)

Fallback origin for *_url outside a request context (jobs, Jbuilder partials) — the default_url_options host analogue.

Source
polymorphic_path(models : Array(ActionView::FormModel)) : String

Polymorphic model→path (the Rails polymorphic_path analogue for ActionView::FormModel arrays): computes the named route from the models' names + persisted? state and fills the dynamic segments with the models' to_params — [room, message(persisted)] → room_message_path(room, message) [room, Message.new] → room_messages_path(room) [message(persisted)] → message_path(message) [Message.new] → messages_path action_view_cr's form_with calls this through FormHelper.polymorphic_path, wired here by railties_cr at boot — action_view_cr cannot reach the route set itself (the dependency runs action_pack_cr → action_view_cr, not the other way).

Source
route_set

Route set the generated helpers resolve against. The application (railties_cr) points this at CRails.application.routes at boot; specs assign their own. action_pack_cr cannot reach CRails.application itself (railties_cr depends on action_pack_cr, not vice versa).

Source
route_set=(route_set : RouteSet | Nil)

Route set the generated helpers resolve against. The application (railties_cr) points this at CRails.application.routes at boot; specs assign their own. action_pack_cr cannot reach CRails.application itself (railties_cr depends on action_pack_cr, not vice versa).

Source

Macros

method_missing(call)
Source