Skip to content

Veins (routing)

Veins maps incoming requests to controller actions. Routes live in config/routes.am, inside a Rocks.routes block whose self is a Veins::Router. Every method below is statically typed, so a typo in your routes fails the build instead of returning 404s to your customers.

def Rocks.routes(&block: () -> Void with Veins::Router): Void
config/routes.am
Rocks.routes do
root "pages#home"
get "/about", to: "pages#about"
post "/contact", to: "contact#create"
end

"pages#about" means the about action on PagesController. Veins checks at compile time that both exist. It’s very thorough and doesn’t get invited to many parties.

Method HTTP verb
get GET
post POST
put / patch PUT / PATCH
delete DELETE

resources declares the standard CRUD routes for a resource in one line:

resources :posts
Verb Path Action Purpose
GET /posts index List posts
GET /posts/new new Form for a new post
POST /posts create Create a post
GET /posts/:id show Show one post
GET /posts/:id/edit edit Form to edit a post
PATCH /posts/:id update Update a post
DELETE /posts/:id destroy Delete a post

Limit the set with only: or except::

resources :sessions, only: [:new, :create, :destroy]
resources :photos, except: [:edit, :update]

Resources nest, as veins do:

resources :posts do
resources :comments, only: [:create, :destroy]
end

This adds POST /posts/:post_id/comments and DELETE /posts/:post_id/comments/:id. Please don’t nest more than two deep. Geologists call that a “fault”.

Segments starting with : are passed to the action as arguments with the same name, and converted to the parameter’s declared type:

get "/archive/:year/:month", to: "archive#show"
class ArchiveController < Rocks::Controller
def show(year: Int, month: Int): Response
# GET /archive/2026/12 → year = 2026, month = 12
# GET /archive/soon/ish → 404, before your code even runs
end
end
namespace :admin do
resources :users
end

Routes /admin/users to Admin::UsersController.

Every named route gets a typed path helper, available in controllers and views:

posts_path # "/posts"
post_path(post) # "/posts/42"
edit_post_path(post) # "/posts/42/edit"

Because they’re methods, a helper for a route that doesn’t exist is a compile error. Broken links: now a build-time problem. Your QA team may send flowers.