class

CRails::Routes::Drawer

Inherits Reference < Object

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

new(set : RouteSet)
Source

Instance methods

collection

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.

Source
delete(path : String, *, file : String = __FILE__, line : Int32 = __LINE__, **opts) : Nil
Source
get(path : String, *, file : String = __FILE__, line : Int32 = __LINE__, **opts) : Nil
Source
member
Source
namespace(name : String | Symbol, &) : Nil

namespace :admin — scope(path: "admin", module: "admin", as: "admin"): /admin/posts -> admin/posts#index.

Source
openapi(path : String = "/openapi.json", *, file : String = __FILE__, line : Int32 = __LINE__) : Nil

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").

Source
patch(path : String, *, file : String = __FILE__, line : Int32 = __LINE__, **opts) : Nil
Source
post(path : String, *, file : String = __FILE__, line : Int32 = __LINE__, **opts) : Nil
Source
put(path : String, *, file : String = __FILE__, line : Int32 = __LINE__, **opts) : Nil
Source
resource(name : String | Symbol, *, file : String = __FILE__, line : Int32 = __LINE__, **opts) : Nil

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).

Source
resource(name : String | Symbol, *, file : String = __FILE__, line : Int32 = __LINE__, **opts, &) : Nil
Source
resources(name : String | Symbol, *, file : String = __FILE__, line : Int32 = __LINE__, **opts) : Nil

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).

Source
resources(name : String | Symbol, *, file : String = __FILE__, line : Int32 = __LINE__, **opts, &) : Nil
Source
root(to : String, *, file : String = __FILE__, line : Int32 = __LINE__) : Nil
Source
scope

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.

Source