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_paramare 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'soriginmethod when the including context has one (controllers), thenjb_origin(Jbuilder partials), thendefault_url_origin.
Class methods
Rails to_param semantics: objects may customize their URL
representation; everything else goes through to_s.
Fallback origin for *_url outside a request context (jobs,
Jbuilder partials) — the default_url_options host analogue.
Fallback origin for *_url outside a request context (jobs,
Jbuilder partials) — the default_url_options host analogue.
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).
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).
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).