一键导入
define-routes
Use when defining routes in Hanami 2.x. Covers get, post, patch, delete, resources, resource, scope, and named route helpers in config/routes.rb.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when defining routes in Hanami 2.x. Covers get, post, patch, delete, resources, resource, scope, and named route helpers in config/routes.rb.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Master orchestrator for hanakai-yaku, a curated library of 35 atomic skills and 10 personas for Hanami, dry-rb, and ROM Ruby development. Covers actions, slices, repositories, relations, providers, DI, CLI, testing, views, routing, and TDD automation. Enforces Hanami conventions and TDD discipline. hanami, dry-rb, rom, ruby, tdd, slices, repositories, operations, providers, di, actions, views, routing, cli, testing.
Use when implementing a Hanami 2.x feature, Hanami action, Hanami slice, or any Hanami controller logic using test-driven development (TDD / red-green-refactor). Orchestrates test planning, generates request specs or action unit specs, drives the implementation of Hanami action classes and route configurations, and performs a final code review. Use when starting a new Hanami feature from scratch, adding integration tests for an existing Hanami action, or following a red-green-refactor cycle for any Hanami 2.x component.
Orchestrates Hanami project onboarding: loads application context, configures providers, implements dependency injection patterns, and verifies the setup. Use when setting up a new Hanami project, onboarding a developer, configuring services and DI, or wiring up dry-container, dry-system, IoC containers, or Hanami app configuration with providers and dependency injection.
Orchestrates the full Hanami slice lifecycle: creates the slice, tests it in isolation, reviews boundary design, and supports extraction from the app module. Use when building a new Hanami slice, auditing existing slices for bounded context violations, extracting monolithic code into a modular architecture, or enforcing slice generator conventions. Trigger terms: bounded context, Hanami module, modular architecture, slice boundaries, slice extraction, slice generator.
Use when building JSON API endpoints in Hanami 2.x Actions — set `response.format = :json`, use dedicated serializers to encode response bodies, write round-trip serialize→parse tests asserting fields match with `.iso8601` timestamps, include pagination metadata with `{data:, meta:}` shape, return consistent error shapes across endpoints, and rescue `JSON::ParserError` with 400 status. Covers setting content-type headers, serializing Ruby objects to JSON, parsing incoming JSON request bodies, content negotiation, and round-trip parse → serialize → parse verification. Use when you need to render JSON, build a JSON endpoint, create an API controller action, or handle JSON request/response cycles in Hanami 2.x.
Use when creating, generating, or reviewing Hanami 2.x Action classes (route handlers, request handling, hanami controller equivalents). Generates Action classes with proper handle method signatures, configures dependency injection via Deps[], renders views with exposures, validates params, redirects, returns JSON responses, sets HTTP status codes, and implements halt-based error handling. Use when building a hanami action, wiring a new endpoint, handling params, or structuring request/response logic in a Hanami 2.x app.
| name | define-routes |
| license | MIT |
| type | atomic |
| description | Use when defining routes in Hanami 2.x. Covers get, post, patch, delete, resources, resource, scope, and named route helpers in config/routes.rb. |
| metadata | {"ecosystem_sources":["hanami/hanami-router"],"tags":["routing","routes","dsl","http"],"version":"1.0.0"} |
Use this skill when defining routes in Hanami 2.x.
Core principle: Routes map URLs to Actions. They are explicit, readable, and RESTful.
Define routes in config/routes.rb:
# config/routes.rb
module MyApp
class Routes < Hanami::Routes
root to: "home.index"
get "/users", to: "users.index"
get "/users/:id", to: "users.show"
post "/users", to: "users.create"
patch "/users/:id", to: "users.update"
delete "/users/:id", to: "users.destroy"
end
end
Use resources for RESTful routes:
resources :users do
resources :posts
end
Generates:
GET /users → users.indexGET /users/:id → users.showPOST /users → users.createPATCH /users/:id → users.updateDELETE /users/:id → users.destroyUse resource for singular resources (no index):
resource :profile
Name routes for URL generation:
get "/users", to: "users.index", as: :users
get "/users/:id", to: "users.show", as: :user
Access in Views or Actions:
routes.path(:user, id: 1) # => "/users/1"
routes.url(:users) # => "http://example.com/users"
Scope routes for versioning or grouping:
scope "api" do
scope "v1" do
resources :users
end
end
Mount slices at paths:
slice :api, at: "/api" do
resources :users
end
Order matters: Hanami matches routes top-to-bottom. Put specific routes before general ones (wildcards):
# CORRECT: specific first
get "/users/new", to: "users.new"
get "/users/:id", to: "users.show"
After defining routes, inspect all registered routes with the Hanami CLI:
bundle exec hanami routes
This lists every route with its HTTP method, path, and action target. Use it to confirm routes are correctly registered before running tests or the server.
Common pitfalls:
to: identifier.get "/users/:id") appears before a specific one (e.g. get "/users/new"), the specific route will never be reached — always check ordering with hanami routes.config/routes.rb can cause stale routing behaviour.| Related Skill | When to chain |
|---|---|
| create-action | Routes point to Actions. Define routes after Actions exist. |
| create-slice | Slices can define their own routes. Understand slices before nesting routes. |
| write-request-spec (testing) | Test routes by making requests to them. |