CRails::Routes::Drawer
DSL object yielded by CRails.application.routes.draw do ... end.
Mirrors ActionDispatch::Routing: resources/resource (with blocks
for nesting), scope, namespace, member/collection and the
plain verb helpers. Matching is a linear first-match scan, so draw
literal segments before dynamic ones (get "/users/me/..." before
resources :users).
Constructors
Instance methods
Routes inside a resources block are member routes by default;
collection { ... } drops the trailing ":id" segment for the block
(like on: :collection on a single route). member { ... } is
accepted for Rails parity and changes nothing.
namespace :admin — scope(path: "admin", module: "admin", as: "admin"):
/admin/posts -> admin/posts#index.
openapi "/openapi.json" — mount the built-in document endpoint
(CRails::OpenApiController, Iteration 10). Serving is opt-in:
the drawer call is the only wiring needed. Controller key is
"c_rails/open_api": Dispatch.resolve underscores each namespace
segment ("CRails" -> "c_rails").
resource :session — the singular-resource routes Rails draws:
/session/new, POST /session, /session/edit, PATCH+PUT /session,
GET /session, DELETE /session. The controller is the pluralized
name ("sessions"), overridable with controller:. A block nests
routes under the plain path (no :id segment — /session/transfers).
resource :session without a block (see the block form below).
resources :posts — the seven RESTful routes Rails draws for a
resource, in Rails draw order (index, new, edit, show, create,
PATCH+PUT update, destroy). Options: only:/except: (array or
single action), controller:, param: (default "id"), path:,
as:, defaults:. A block nests routes under the member path
(/posts/:post_id/...); plain verb calls inside it are member
routes by default — wrap them in collection { } (or pass
on: :collection) for collection scope.
resources :posts without a block (see the block form below).
scope path: "...", module: "...", as: "...", defaults: {..." —
nests paths, controller modules, route names and default params for
the block. module and as are Crystal keywords, so all options are
read from **opts. A leading "/" in a to: controller ("rooms#show")
opts out of the module prefix, as in Rails.