jutsu-rails

Advanced Ruby on Rails skills for MVC patterns, Active Record, and Hotwire

View on GitHub
Author The Bushido Collective
Namespace @TheBushidoCollective/han
Category Technique
Version 1.0.0
Stars 66
Downloads 4
self.md verified
Table of content

Advanced Ruby on Rails skills for MVC patterns, Active Record, and Hotwire

Installation

npx claude-plugins install @TheBushidoCollective/han/jutsu-rails

Contents

Folders: skills

Files: CHANGELOG.md, README.md

Documentation

Advanced Ruby on Rails skills for MVC patterns, Active Record, and Hotwire

Skills

This plugin provides the following skills:

Usage

Once enabled, Claude will automatically apply these skills when working with relevant code. The plugin provides context and expertise that Claude uses to:

Installation

Install with npx (no installation required):

han plugin install jutsu-rails

License

Licensed under MIT - see repository for details.

Included Skills

This plugin includes 3 skill definitions:

rails-action-controller-patterns

Use when action Controller patterns including routing, filters, strong parameters, and REST conventions.

View skill definition

Rails Action Controller Patterns

Master Action Controller patterns for building robust Rails controllers with proper routing, filters, parameter handling, and RESTful design.

Overview

Action Controller is the component that handles web requests in Rails. It processes incoming requests, interacts with models, and renders responses. Controllers follow the MVC pattern and implement REST conventions by default.

Installation and Setup

Generating Controllers

# Generate a resource controller
rails generate controller Posts index show new create edit update destroy

# Generate a namespaced controller
rails generate controller Admin::Posts index show

# Generate an API-only controller
rails generate controller Api::V1::Posts --no-helper --no-assets

Routing Configuration

# config/routes.rb
Rails.application.routes.draw do
  # RESTful resources
  resources :posts

  # Nested resources
  resources :posts do
    resources :comments
  end

  # Namespaced routes
  namespace :admin do
    resources :posts
  end

  # Custom routes
  get 'about', to: 'pages#about'
  root 'posts#index'
end

Core Patterns

1. Basic Controller Structure

# app/controllers/posts_controller.rb
class PostsController < ApplicationController
  before_action :authenticate_user!, except: [:index, :show]
  before_action :set_post, only: [:show, :edit, :update, :destroy]
  before_action :authorize_post, only: [:edit, :update, :destroy]

  # GET /posts
  def in

...(truncated)

</details>

### rails-active-record-patterns

> Use when active Record patterns including models, associations, queries, validations, and callbacks.

<details>
<summary>View skill definition</summary>

# Rails Active Record Patterns

Master Active Record patterns for building robust Rails models with proper
associations, validations, scopes, and query optimization.

## Overview

Active Record is Rails' Object-Relational Mapping (ORM) layer that connects
model classes to database tables. It implements the Active Record pattern,
where each object instance represents a row in the database and includes both
data and behavior.

## Installation and Setup

### Creating Models

```bash
# Generate a model with migrations
rails generate model User name:string email:string:uniq

# Generate model with associations
rails generate model Post title:string body:text user:references

# Run migrations
rails db:migrate

Database Configuration

# config/database.yml
default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: myapp_development

test:
  <<: *default
  database: myapp_test

production:
  <<: *default
  database: myapp_production
  username: myapp
  password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>

Core Patterns

1. Basic Model Definition

# app/models/user.rb
class User < ApplicationRecord
  # Validations
  validates :email, presence: true, uniqueness: true,
    format: { with: URI::MailTo::EMAIL_REGEXP }
  validates :name, presence: true, length: { minimum: 2, maximum: 50 }

  # Callbacks
  before_save :normalize_email
  after_create :send_welcome_email


...(truncated)

</details>

### rails-hotwire

> Use when hotwire (Turbo and Stimulus) for building modern reactive Rails applications without complex JavaScript frameworks.

<details>
<summary>View skill definition</summary>

# Rails Hotwire

Master Hotwire for building modern, reactive Rails applications using Turbo
and Stimulus without requiring heavy JavaScript frameworks.

## Overview

Hotwire (HTML Over The Wire) is a modern approach to building web applications
that sends HTML instead of JSON over the wire. It consists of Turbo (for
delivering server-rendered HTML) and Stimulus (for JavaScript sprinkles).

## Installation and Setup

### Installing Hotwire

```bash
# Add to Gemfile
bundle add turbo-rails stimulus-rails

# Install Turbo
rails turbo:install

# Install Stimulus
rails stimulus:install

# Install Redis for ActionCable (Turbo Streams)
bundle add redis

# Configure ActionCable
rails generate channel turbo_stream

Configuration

# config/cable.yml
development:
  adapter: redis
  url: redis://localhost:6379/1

production:
  adapter: redis
  url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
  channel_prefix: myapp_production

# config/routes.rb
Rails.application.routes.draw do
  mount ActionCable.server => '/cable'
end

Core Patterns

1. Turbo Drive (Page Acceleration)

# Turbo Drive is automatic, but you can customize behavior

# app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
  <head>
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>
    <%= turbo_refreshes_with method: :morph, scroll: :preserve %>
  </head>
  <body>
    <%= yield %>
  </body>
</html>

# Disable Turbo for specific links
<%= link_to "Legacy Page", legacy

...(truncated)

</details>

## Source

[View on GitHub](https://github.com/TheBushidoCollective/han)