CtrlK
BlogDocsLog inGet started
Tessl Logo

igmarin/hanakai-yaku

Curated library of atomic AI agent skills for Hanami, dry-rb, and ROM Ruby development. Covers actions, slices, repositories, relations, changesets, providers, DI, operations, TDD, CLI, views, routing, and validation. Shared Ruby process skills have moved to ruby-core-skills. Uses Markdown + Front-matter architecture.

92

1.33x
Quality

94%

Does it follow best practices?

Impact

92%

1.33x

Average score across 35 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

SKILL.mdskills/actions/create-action/

name:
create-action
license:
MIT
description:
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.
metadata:
{"ecosystem_sources":["hanami/hanami-controller"],"tags":["actions","http","controllers","endpoints"],"version":"1.0.0"}

create-action

Use this skill when creating or reviewing Hanami 2.x Actions.

Core principle: One Action = one HTTP endpoint.


Quick Reference (jump to workflow step)

ScenarioWorkflow Step
Create a new ActionStep 1: Generate
Validate / coerce paramsStep 2: Params block
Implement request logicStep 3: #handle
Inject dependenciesStep 4: Deps[]
Handle errors / haltStep 5: Error handling
Set HTTP status codesStep 6: Status codes
Test the actionStep 7: Request spec

Workflow: Creating a New Action

  1. Generate the Action file. One Action per file — generate Index, Show, Create, Update, Destroy as separate classes:

    hanami generate action Users::Index
  2. Define a Params block to validate and coerce input. Invalid params should halt 422 before any business logic runs:

    class Create < MyApp::Action
      params do
        required(:user).hash do
          required(:name).filled(:string)
          required(:email).filled(:string)
        end
      end
    
      def handle(request, response)
        halt 422, { errors: request.params.errors.to_h }.to_json unless request.params.valid?
        # proceed with valid params
      end
    end
  3. Implement #handle — Actions are HTTP handlers only; delegate all business logic to repositories, interactors, or service objects. Actions have only #handle; never use instance variables for state sharing between methods:

    # app/actions/users/index.rb
    # frozen_string_literal: true
    
    module MyApp
      module Actions
        module Users
          class Index < MyApp::Action
            include Deps["repos.user_repo"]
    
            def handle(request, response)
              response.render(view, users: user_repo.all)
            end
          end
        end
      end
    end
  4. Inject dependencies via Deps — never access the container directly (Hanami.app['key'] is untestable and forbidden):

    include Deps["repos.user_repo", "views.users.show"]
  5. Wire error handling — use halt for early returns. Log errors and return meaningful responses; never swallow exceptions silently:

    def handle(request, response)
      user = user_repo.by_id(request.params[:id]).one
      halt 404, { error: "User not found" }.to_json unless user
      response.render(view, user: user)
    end
  6. Set appropriate HTTP status codes where they differ from defaults:

    • 201 for successful creates
    • 204 for successful deletes with no body
    • 422 for validation errors

    To return JSON: response.format = :json; response.body = data.to_json To redirect: response.redirect_to("/path")

  7. Validate with a request spec (see write-request-spec skill) before considering the action complete.


Integration

Related SkillWhen to chain
create-repositoryActions inject Repositories to fetch and persist data.
create-viewActions render Views by passing exposures.
validate-paramsActions define Params blocks to validate input.
handle-errorsActions use halt for early returns and error responses.
inject-dependenciesActions use include Deps[] for dependency injection.
write-request-spec (testing)Test Actions via Rack request specs.

skills

actions

create-action

README.md

tile.json