### Dockerfile: Install Gems and Copy Application Code Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-deployment/references/examples.md This snippet shows the initial steps in a Dockerfile for a Rails application. It copies the Gemfile and Gemfile.lock, installs gems using bundle install, and then copies the rest of the application code. It also includes commands to precompile bootsnap code for faster boot times. ```dockerfile COPY Gemfile Gemfile.lock ./ RUN bundle install && \ rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ bundle exec bootsnap precompile --gemfile # Copy application code COPY . . # Precompile bootsnap code for faster boot times RUN bundle exec bootsnap precompile app/ lib/ ``` -------------------------------- ### Setup Remote Server for Docker Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-deployment/SKILL.md Installs Docker on the remote server using Kamal and then verifies the server setup. This prepares the target environment for deployment. ```bash # Install Docker on remote server kamal server bootstrap # Verify setup kamal setup ``` -------------------------------- ### Install and Generate Devise User Model (Bash) Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-auth-with-devise/SKILL.md Installs the Devise gem and generates the User model with authentication capabilities. This is the initial setup step for Devise in a Rails application. ```bash bundle add devise rails generate devise:install rails generate devise User rails db:migrate ``` -------------------------------- ### Bulk Admin User Creation via Seeds or Migration Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md Provides a script for bulk creation or updating of admin users using their email addresses. This can be integrated into `db/seeds.rb` or a Rails migration for initial setup or updates. ```ruby # db/seeds.rb or migration admin_emails = [ "ops_lead@company.com", "dev_lead@company.com", "support_manager@company.com" ] admin_emails.each do |email| user = User.find_or_create_by(email: email) user.update!(admin: true) end ``` -------------------------------- ### Install and Configure Kaminari Gem Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-pagination-kaminari/SKILL.md Steps to add the Kaminari gem to your Rails project, generate configuration files, and create view templates for customization. This is the initial setup for enabling pagination. ```bash # Add to Gemfile bundle add kaminari # Generate configuration file (optional) rails g kaminari:config # Generate view templates for customization (optional) rails g kaminari:views default ``` -------------------------------- ### Kamal Multi-Server Setup with Load Balancing (YAML) Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-deployment/references/examples.md Configures Kamal for a multi-server deployment, including load balancing for web servers and separate servers for background jobs. It defines hosts, Traefik labels, network settings, registry credentials, environment variables, builder configuration, Traefik setup on a dedicated host, and health checks. ```yaml #config/deploy.yml service: my-app image: username/my-app servers: web: hosts: - 192.168.1.101 - 192.168.1.102 - 192.168.1.103 labels: traefik.http.routers.my-app.rule: Host(`app.example.com`) traefik.http.routers.my-app-secure.entrypoints: websecure traefik.http.routers.my-app-secure.rule: Host(`app.example.com`) traefik.http.routers.my-app-secure.tls: true traefik.http.routers.my-app-secure.tls.certresolver: letsencrypt options: network: "private" # Separate worker servers for background jobs workers: hosts: - 192.168.1.104 - 192.168.1.105 cmd: bundle exec rake solid_queue:start options: network: "private" registry: username: username password: - KAMAL_REGISTRY_PASSWORD env: secret: - RAILS_MASTER_KEY - DATABASE_URL clear: RAILS_ENV: production RAILS_LOG_TO_STDOUT: enabled WEB_CONCURRENCY: 3 RAILS_MAX_THREADS: 5 builder: arch: amd64 traefik: host_port: 192.168.1.100 # Dedicated load balancer options: publish: - 443:443 - 80:80 volume: - "/letsencrypt:/letsencrypt" network: "private" args: entryPoints.web.address: ":80" entryPoints.websecure.address: ":443" certificatesResolvers.letsencrypt.acme.email: "admin@example.com" certificatesResolvers.letsencrypt.acme.storage: "/letsencrypt/acme.json" certificatesResolvers.letsencrypt.acme.httpchallenge: true certificatesResolvers.letsencrypt.acme.httpchallenge.entrypoint: web healthcheck: path: /up port: 3000 max_attempts: 10 interval: 10s ``` -------------------------------- ### Install Fullstack Preset Generator Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/CONTRIBUTING.md Command to run the 'fullstack' preset of the Claude installation generator. This sets up a comprehensive environment for using Claude skills. ```bash rails g claude:install --preset=fullstack ``` -------------------------------- ### Optimized Multi-Stage Dockerfile for Rails (Dockerfile) Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-deployment/references/examples.md An optimized multi-stage Dockerfile for building Rails application images. It uses a slim Ruby base image, installs necessary packages, sets production environment variables, and configures memory allocation for performance. The build stage installs development dependencies required for compilation. ```dockerfile #syntax = docker/dockerfile:1 ARG RUBY_VERSION=3.4.7 FROM ruby:$RUBY_VERSION-slim AS base # Set working directory WORKDIR /rails # Install base packages RUN apt-get update -qq && \ apt-get install --no-install-recommends -y \ curl \ libjemalloc2 \ libvips \ sqlite3 && \ rm -rf /var/lib/apt/lists /var/cache/apt/archives # Set production environment ENV RAILS_ENV="production" \ BUNDLE_DEPLOYMENT="1" \ BUNDLE_PATH="/usr/local/bundle" \ BUNDLE_WITHOUT="development:test" \ MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:5000,muzzy_decay_ms:5000" # Build stage FROM base AS build # Install build packages RUN apt-get update -qq && \ apt-get install --no-install-recommends -y \ build-essential \ git \ pkg-config && \ rm -rf /var/lib/apt/lists /var/cache/apt/archives ``` -------------------------------- ### Dockerfile: Precompile Assets and Final Stage Setup Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-deployment/references/examples.md This part of the Dockerfile focuses on precompiling Rails assets and setting up the final image stage. It precompiles assets, copies built artifacts from a previous build stage, creates a dedicated user for running the application, and sets the user and entrypoint. ```dockerfile # Precompile assets RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile # Final stage FROM base # Copy built artifacts COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}" COPY --from=build /rails /rails # Create user RUN groupadd --system --gid 1000 rails && \ useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \ chown -R rails:rails db log storage tmp USER 1000:1000 # Entrypoint ENTRYPOINT ["/rails/bin/docker-entrypoint"] EXPOSE 3000 CMD ["./bin/thrust", "./bin/rails", "server"] ``` -------------------------------- ### Add Database Indexes for SolidQueue Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md This SQL snippet provides commands to add database indexes to the `solid_queue_jobs` table. These indexes are recommended for improving the performance of dashboard loading and job querying, especially in large databases. ```sql add_index :solid_queue_jobs, [:queue_name, :status] add_index :solid_queue_jobs, [:status, :created_at] ``` -------------------------------- ### Environment Variables: Local .env File Example Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-deployment/references/examples.md An example of a .env file used for local development. This file should not be committed to version control and contains environment-specific variables like API keys and database URLs. ```dotenv # .env (local only, not committed) KAMAL_REGISTRY_PASSWORD=docker_hub_password RAILS_MASTER_KEY=abc123... DATABASE_URL=postgresql://user:pass@host:5432/dbname SMTP_USERNAME=apikey SMTP_PASSWORD=sendgrid_key ``` -------------------------------- ### Kamal Basic Single-Server Setup (YAML) Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-deployment/references/examples.md Configures Kamal for a basic single-server deployment of a Rails application. It specifies the service name, Docker image, server host, Traefik routing rules, registry credentials, environment variables, build settings, Traefik configuration, and health check parameters. ```yaml #config/deploy.yml service: my-blog-app image: username/my-blog-app servers: web: hosts: - 192.168.1.100 labels: traefik.http.routers.my-blog-app.rule: Host(`blog.example.com`) traefik.http.routers.my-blog-app-secure.entrypoints: websecure traefik.http.routers.my-blog-app-secure.rule: Host(`blog.example.com`) traefik.http.routers.my-blog-app-secure.tls: true traefik.http.routers.my-blog-app-secure.tls.certresolver: letsencrypt registry: username: username password: - KAMAL_REGISTRY_PASSWORD env: secret: - RAILS_MASTER_KEY clear: RAILS_ENV: production RAILS_LOG_TO_STDOUT: enabled RAILS_SERVE_STATIC_FILES: enabled builder: arch: amd64 remote: host: 192.168.1.100 traefik: options: publish: - 443:443 - 80:80 volume: - "/letsencrypt:/letsencrypt" args: entryPoints.web.address: ":80" entryPoints.websecure.address: ":443" certificatesResolvers.letsencrypt.acme.email: "admin@example.com" certificatesResolvers.letsencrypt.acme.storage: "/letsencrypt/acme.json" certificatesResolvers.letsencrypt.acme.httpchallenge: true certificatesResolvers.letsencrypt.acme.httpchallenge.entrypoint: web healthcheck: path: /up port: 3000 max_attempts: 10 interval: 10s ``` -------------------------------- ### Install Rswag for API Documentation in Rails Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-api-controllers/references/api-documentation.md This snippet shows how to add the Rswag gem to your Gemfile and install it using `bundle install` and `rails g rswag:install`. This process sets up the necessary files for OpenAPI/Swagger documentation generation within a Rails application. ```ruby # Gemfile group :development, :test do gem 'rswag' end # Install bundle install rails g rswag:install ``` -------------------------------- ### Install and Verify Kamal Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-deployment/SKILL.md Installs the Kamal gem and verifies its installation by checking the version. This is the first step in setting up Kamal for Rails deployments. ```bash gem install kamal kamal version ``` -------------------------------- ### Dockerfile for Ruby Application Optimization Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-deployment/references/examples.md This Dockerfile optimizes a Ruby application image by using a specific Ruby version, reducing layer count with multi-command RUN, copying only necessary files, and installing gems efficiently. It also suggests using a .dockerignore file to exclude unnecessary files. ```dockerfile # Use specific Ruby version ARG RUBY_VERSION=3.4.7 FROM ruby:$RUBY_VERSION-slim # Reduce layer count with multi-command RUN RUN apt-get update -qq && \ apt-get install --no-install-recommends -y pkg1 pkg2 && \ rm -rf /var/lib/apt/lists /var/cache/apt/archives # Copy only what's needed COPY Gemfile Gemfile.lock ./ RUN bundle install # Use .dockerignore to exclude unnecessary files ``` -------------------------------- ### Skill File Format Example Source: https://context7.com/shoebtamboli/rails_claude_skills/llms.txt Markdown example demonstrating the structure of a skill file, including YAML frontmatter for metadata (name, description, version, tags) and the body containing knowledge, patterns, and code examples for Claude. ```markdown --- name: custom-domain description: Domain-specific patterns for your application version: 1.0.0 rails_version: ">= 7.0" tags: - custom - domain --- # Custom Domain Skill ## Quick Reference | Pattern | Example | |---------|---------| | **Create** | `DomainService.new(params).call` | | **Query** | `DomainQuery.new.execute` | ## Overview Description of domain patterns and conventions. ## Code Patterns ```ruby class DomainService def initialize(params) @params = params end def call # Business logic here end end ``` ## Best Practices - Use service objects for complex operations - Keep models focused on data persistence - Validate at application and database level ``` -------------------------------- ### Mount Mission Control Engine with Authentication Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md This Ruby code shows how to mount the Mission Control Jobs Engine in a Rails application. It demonstrates the secure way to do this by requiring user authentication and checking for admin privileges before mounting the engine. This prevents unauthorized access to the job management interface. ```ruby # ❌ NEVER do this in production # mount MissionControl::Jobs::Engine, at: "/jobs" # ✅ Always authenticate authenticate :user, ->(user) { user.admin? } do mount MissionControl::Jobs::Engine, at: "/jobs" end ``` -------------------------------- ### Initial Project Setup for Rails Claude Skills Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/CLAUDE.md The command to perform the initial setup of the Rails Claude Skills project after cloning the repository. ```bash # Initial setup after cloning bin/setup ``` -------------------------------- ### Add Mission Control Jobs Gem Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md Adds the mission_control-jobs gem to your project's Gemfile and installs it using bundle install. This is the first step in integrating Mission Control Jobs. ```ruby # Gemfile gem "mission_control-jobs" bundle install ``` -------------------------------- ### Turbo Streams Controller Setup in Rails Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-hotwire/SKILL.md Demonstrates how to set up controllers in Rails to respond with Turbo Streams formats for actions like create, update, and destroy. This enables real-time updates to the client. ```ruby class PostsController < ApplicationController def create @post = Post.new(post_params) respond_to do |format| if @post.save format.turbo_stream format.html { redirect_to @post } else format.turbo_stream { render :form_errors, status: :unprocessable_entity } format.html { render :new, status: :unprocessable_entity } end end end def update respond_to do |format| if @post.update(post_params) format.turbo_stream format.html { redirect_to @post } else format.turbo_stream { render :form_errors, status: :unprocessable_entity } format.html { render :edit, status: :unprocessable_entity } end end end def destroy @post.destroy respond_to do |format| format.turbo_stream { render turbo_stream: turbo_stream.remove(@post) } format.html { redirect_to posts_path } end end end ``` -------------------------------- ### GET /health/jobs Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md Retrieves the health status of the job processing system, including counts of pending and failed jobs, and the age of the oldest pending job. ```APIDOC ## GET /health/jobs ### Description Retrieves the health status of the job processing system. It provides counts of pending and failed jobs, and the age of the oldest pending job. The status is 'healthy' if the oldest pending job is less than 30 minutes old and there are fewer than 100 failed jobs; otherwise, it's 'degraded'. ### Method GET ### Endpoint /health/jobs ### Parameters #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **status** (string) - The health status of the job system ('healthy' or 'degraded'). - **pending_jobs** (integer) - The number of jobs currently pending. - **failed_jobs** (integer) - The number of jobs that have failed. - **oldest_pending_minutes** (integer) - The age of the oldest pending job in minutes. #### Response Example ```json { "status": "healthy", "pending_jobs": 42, "failed_jobs": 3, "oldest_pending_minutes": 2 } ``` #### Error Response (e.g., 503 Service Unavailable) ```json { "status": "degraded", "pending_jobs": 150, "failed_jobs": 105, "oldest_pending_minutes": 35 } ``` ``` -------------------------------- ### Log Mission Control Access Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md This Ruby code defines a controller concern to log access to the Mission Control dashboard. It checks if the request path starts with '/jobs' and, if so, logs the current user's email and IP address. This helps in auditing who is accessing the job management interface. ```ruby class ApplicationController < ActionController::Base before_action :log_mission_control_access, if: :mission_control_request? private def mission_control_request? request.path.start_with?('/jobs') end def log_mission_control_access Rails.logger.info( "Mission Control accessed by #{current_user&.email} " \ "from #{request.remote_ip}" ) end end ``` -------------------------------- ### Make Docker Entrypoint Executable Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-deployment/references/examples.md A simple command to make the Docker entrypoint script executable. ```bash # Make executable chmod +x bin/docker-entrypoint ``` -------------------------------- ### Configure Job Health Endpoint Route Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md This Ruby code snippet defines a route for the job health check endpoint in a Rails application. It maps GET requests to '/health/jobs' to the 'jobs' action within the 'health' controller. This allows external monitoring tools to access the health status. ```ruby get '/health/jobs', to: 'health#jobs' ``` -------------------------------- ### Manual Deployment Workflow with GitHub Actions Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-deployment/references/examples.md This GitHub Actions workflow allows for manual deployment to different environments (staging or production) based on user input. It checks out the code and then uses Kamal to deploy, conditionally specifying the configuration file based on the selected environment. ```yaml name: Manual Deploy on: workflow_dispatch: inputs: environment: description: "Environment to deploy" required: true type: choice options: - staging - production jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Deploy to ${{ inputs.environment }} run: | if [ "${{ inputs.environment }}" = "staging" ]; then kamal deploy -c config/deploy.staging.yml else kamal deploy -c config/deploy.yml fi ``` -------------------------------- ### Example Command File for Database Migration Source: https://context7.com/shoebtamboli/rails_claude_skills/llms.txt Markdown example of a command file for the `/dbchange` slash command, detailing its description, argument hints, allowed tools, and providing instructions for generating a migration with safety checks and post-generation considerations. ```markdown --- description: Generate a database migration with safety checks argument-hint: [migration_description] allowed-tools: Bash, Read, Edit --- Generate a migration: $ARGUMENTS Safety checklist: 1. Use reversible migrations when possible 2. Add indexes for foreign keys 3. Use `change` method instead of up/down when possible 4. Consider data migration needs 5. Add comments for complex changes After generation: - Review the migration file - Check for potential downtime issues - Suggest background migration if needed for large tables ``` -------------------------------- ### Troubleshooting Common Deployment Issues with Kamal Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-deployment/references/examples.md This collection of bash commands aids in troubleshooting common deployment issues with Kamal. It includes commands for checking application logs and containers, server resources (memory and disk space), database connectivity, restarting services, and performing a complete cleanup and redeploy. ```bash # Container not starting kamal app logs -f kamal app containers # Check server resources kamal app exec "free -h" kamal app exec "df -h" # Database connection issues kamal app exec "bin/rails db:version" kamal app exec "bin/rails console" # Restart services kamal app restart kamal traefik restart # Complete cleanup and redeploy kamal app remove kamal deploy ``` -------------------------------- ### Kamal Staging and Production Environments (YAML & Bash) Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-deployment/references/examples.md Demonstrates configuring separate Kamal deployment files for staging and production environments. It shows how to define distinct service names, server hosts, Traefik rules, and environment variables for each environment. Includes bash commands to deploy to each environment. ```yaml #config/deploy.yml (production) service: my-app-production image: username/my-app servers: web: hosts: - production.example.com labels: traefik.http.routers.my-app-prod.rule: Host(`app.example.com`) env: secret: - RAILS_MASTER_KEY clear: RAILS_ENV: production ``` ```yaml #config/deploy.staging.yml (staging) service: my-app-staging image: username/my-app servers: web: hosts: - staging.example.com labels: traefik.http.routers.my-app-staging.rule: Host(`staging.app.example.com`) env: secret: - RAILS_MASTER_KEY clear: RAILS_ENV: staging ``` ```bash # Deploy to staging kamal deploy -c config/deploy.staging.yml # Deploy to production kamal deploy -c config/deploy.yml ``` -------------------------------- ### SolidQueue Job Management Operations Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md Common operations for managing SolidQueue jobs, including retrying failed jobs, discarding jobs, and pausing/resuming queue processing. ```APIDOC ## SolidQueue Job Management Operations ### Retry All Failed Jobs This operation retries all jobs that are currently in a failed state. **Method:** Rails Console **Code:** ```ruby SolidQueue::Job.failed.find_each(&:retry!) ``` **Alternative (Mission Control UI):** 1. Navigate to the 'Failed Jobs' tab. 2. Select all jobs. 3. Click the 'Retry Selected' button. ### Discard Specific Failed Jobs This operation permanently removes failed jobs based on criteria like age or job class. **Method:** Rails Console **Code (Discard jobs older than 1 week):** ```ruby SolidQueue::Job.failed.where("failed_at < ?", 1.week.ago).delete_all ``` **Code (Discard jobs of a specific class):** ```ruby SolidQueue::Job.failed.where(class_name: "ProblematicJob").delete_all ``` ### Pause/Resume Queue Processing SolidQueue does not directly support pausing/resuming. This is achieved by scaling worker processes to zero. **Method:** Configuration Change **Configuration (`config/queue.yml` - temporary): ```yaml production: workers: - queues: [critical, mailers] threads: 5 processes: 0 # Set to 0 to pause processing ``` After modifying `queue.yml`, workers need to be restarted. ### Monitor Specific Queue This operation allows you to check the number of pending and failed jobs for a specific queue. **Method:** Rails Console **Code (Monitor 'mailers' queue): ```ruby SolidQueue::Job.where(queue_name: "mailers").pending.count SolidQueue::Job.where(queue_name: "mailers").failed.count ``` ``` -------------------------------- ### Update CHANGELOG.md Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/CONTRIBUTING.md Example of how to update the CHANGELOG.md file to document new additions, fixes, or changes. This is a key step before submitting changes. ```markdown ## [Unreleased] ### Added - New skill: rails-action-mailer ### Fixed - Install generator typo in basic preset ### Changed - Simplified skill generator templates ``` -------------------------------- ### Automated Deployment Workflow with GitHub Actions Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-deployment/references/examples.md This GitHub Actions workflow automates the testing and deployment of a Rails application. It checks out the code, sets up Ruby with Bundler caching, runs tests and RuboCop, and then deploys using Kamal, requiring secrets for registry password and Rails master key. ```yaml name: Deploy on: push: branches: [main] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: bundler-cache: true - name: Run tests run: | bin/rails test bin/rubocop deploy: needs: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: bundler-cache: true - name: Install Kamal run: gem install kamal - name: Setup SSH uses: webfactory/ssh-agent@v0.8.0 with: ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - name: Deploy with Kamal env: KAMAL_REGISTRY_PASSWORD: ${{ secrets.KAMAL_REGISTRY_PASSWORD }} RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }} run: | kamal deploy ``` -------------------------------- ### Setup SimpleCov for Rails Test Coverage Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/minitest-testing/references/examples.md Configures SimpleCov to track code coverage for a Rails application. It specifies which directories to filter and groups code by type (Models, Controllers, Jobs, Mailers). ```ruby require "simplecov" SimpleCov.start "rails" do add_filter "/test/" add_filter "/config/" add_group "Models", "app/models" add_group "Controllers", "app/controllers" add_group "Jobs", "app/jobs" add_group "Mailers", "app/mailers" end ENV["RAILS_ENV"] ||= "test" require_relative "../config/environment" require "rails/test_help" ``` -------------------------------- ### Complete Rails Project Setup with Claude Skills Source: https://context7.com/shoebtamboli/rails_claude_skills/llms.txt Bash commands demonstrating the complete workflow for setting up a new Rails project with the Rails Claude Skills gem, including creating a new Rails application, adding the gem to the Gemfile, and initializing the gem with a fullstack preset. ```bash # 1. Create new Rails application rails new blog_app --css=tailwind cd blog_app # 2. Add the gem to development group echo "gem 'rails_claude_skills', group: :development" >> Gemfile bundle install # 3. Initialize with fullstack preset rails g claude:install --preset=fullstack ``` -------------------------------- ### Configure Sensitive Parameter Filtering in Rails Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md Configures MissionControl::Jobs to filter sensitive parameters (like passwords and tokens) from being displayed in the dashboard. This enhances security by preventing the exposure of confidential information. ```ruby MissionControl::Jobs.configure do |config| # Filter these parameter keys from display config.filter_parameters = [ :password, :token, :secret, :api_key, :private_key, :access_token, :refresh_token, :credit_card, :ssn ] end ``` -------------------------------- ### Command Frontmatter Example (YAML) Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/CLAUDE.md Illustrates the YAML frontmatter for a command markdown file, including description, argument hints, and allowed tools. ```yaml --- description: Command description argument-hint: [optional_args] allowed-tools: Bash, Read, Edit, Write --- ``` -------------------------------- ### Task List Structure for Rails Feature Development Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/plan-feature/SKILL.md An example of a structured task list for planning Rails feature development. Tasks are ordered logically from database setup to review and polish, ensuring a comprehensive approach. ```text 1. **Database setup** - Migrations, models, associations 2. **Business logic** - Validations, scopes, methods 3. **Controllers & routes** - RESTful actions, authorization 4. **Views & frontend** - Forms, Turbo Frames, TailwindCSS 5. **Testing** - Model, controller, system tests 6. **Review & polish** - Linters, security scan, browser testing ``` -------------------------------- ### Project Settings for Basic Preset Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/README.md Example of the `.claude/settings.local.json` file for the basic preset, defining skill loading, agent paths, and the default model. ```json { "skills": { "autoLoad": true, "path": ".claude/skills" }, "agents": { "path": ".claude/agents", "default": "rails-developer" }, "model": "sonnet", "project": "MyRailsApp", "rails_version": "7.1.3" } ``` -------------------------------- ### Force SSL in Production Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md This Ruby code snippet configures a Rails application to force all connections to use HTTPS in the production environment. This is a crucial security measure to encrypt data in transit between the client and the server. ```ruby # config/environments/production.rb config.force_ssl = true ``` -------------------------------- ### Manually Clean Up Old Jobs in Rails Console Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md Provides manual commands to clean up finished and failed jobs from the database based on their timestamps. This is useful for immediate cleanup or when automated cleanup needs to be supplemented. ```ruby # Rails console SolidQueue::Job.finished.where("finished_at < ?", 14.days.ago).delete_all SolidQueue::Job.failed.where("failed_at < ?", 90.days.ago).delete_all ``` -------------------------------- ### Publishing Documentation - Static Site Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-api-controllers/references/api-documentation.md Steps to generate static HTML documentation from a Swagger/OpenAPI file using `swagger-ui-cli` and serve it. ```APIDOC ## Publishing Documentation ### Static Site ```bash # Generate static HTML docker run -v $(pwd)/swagger:/swagger \ swaggerapi/swagger-ui \ swagger-ui-cli bundle /swagger/v1/swagger.yaml # Serve static files ``` ``` -------------------------------- ### Setup and Testing Commands Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/README.md Commands to set up the development environment for the rails_claude_skills gem and run tests. ```bash bin/setup rake spec bin/console ``` -------------------------------- ### Define User Roles and Access Control in Rails Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md Defines user roles using enums and implements a method to check access to the jobs dashboard. This is crucial for role-based access control within the application. ```ruby class User < ApplicationRecord enum role: { user: 0, developer: 1, operations: 2, admin: 3 } def can_access_jobs_dashboard? developer? || operations? || admin? end end ``` -------------------------------- ### Bundle Swagger UI with Docker (Bash) Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-api-controllers/references/api-documentation.md Provides a Docker command to bundle a Swagger UI static site from a YAML specification file. This command mounts the local swagger directory into the container and executes the `swagger-ui-cli` to generate the bundled HTML files. ```bash # Generate static HTML docker run -v $(pwd)/swagger:/swagger \ swaggerapi/swagger-ui \ swagger-ui-cli bundle /swagger/v1/swagger.yaml # Serve static files ``` -------------------------------- ### Grant Admin Access to User in Rails Console Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md Demonstrates how to grant admin privileges to a specific user in a production Rails environment using the Rails console. This is useful for manually assigning administrative roles. ```ruby # Rails console (production) rails console # Grant admin access to user user = User.find_by(email: "teammate@company.com") user.update!(admin: true) # Or using role enum user.update!(role: :admin) ``` -------------------------------- ### HTTP Basic Auth for Mission Control (Staging/Internal) Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md Configures HTTP Basic Authentication for Mission Control Jobs, suitable for staging or internal tools. It requires setting `MISSION_CONTROL_USERNAME` and `MISSION_CONTROL_PASSWORD` environment variables. ```ruby # config/routes.rb Rails.application.routes.draw do # Add constraint for HTTP Basic Auth constraints(->(req) { authenticate_mission_control(req) }) do mount MissionControl::Jobs::Engine, at: "/jobs" end end # config/application.rb or initializer def authenticate_mission_control(request) return true if Rails.env.development? authenticate_or_request_with_http_basic do |username, password| username == ENV['MISSION_CONTROL_USERNAME'] && password == ENV['MISSION_CONTROL_PASSWORD'] end end # .env or production secrets # MISSION_CONTROL_USERNAME=admin # MISSION_CONTROL_PASSWORD=secure_random_password_here ``` -------------------------------- ### Docker Entrypoint Script: Database Migrations and Execution Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-deployment/references/examples.md This bash script serves as the Docker entrypoint for a Rails application. It removes a stale server PID file, runs database migrations if the DATABASE_URL environment variable is set, and then executes the command passed to the container. ```bash #!/bin/bash -e # bin/docker-entrypoint # Remove pre-existing server.pid rm -f /rails/tmp/pids/server.pid # Run migrations if DATABASE_URL is set if [ -n "$DATABASE_URL" ]; then echo "Running database migrations..." bundle exec rails db:prepare fi # Execute CMD exec "${@}" ``` -------------------------------- ### Clean Up Old Finished Jobs Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md This Ruby code demonstrates how to clean up old finished SolidQueue jobs from the database. It deletes jobs that finished more than 7 days ago. This is a recommended practice for maintaining database performance. ```ruby SolidQueue::Job.finished.where("finished_at < ?", 7.days.ago).delete_all ``` -------------------------------- ### Filter Rails Logs by Severity or Request Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-debugging/SKILL.md Search through Rails log files to pinpoint specific issues. You can filter logs by error severity (e.g., 'ERROR') or by request details (e.g., 'Started GET') to quickly find relevant information. ```bash grep ERROR log/production.log ``` ```bash grep "Started GET" log/development.log ``` -------------------------------- ### Basic JSONAPI::Serializer Setup Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-api-controllers/references/serialization.md Illustrates how to define a basic serializer using JSONAPI::Serializer, including attributes and relationships. This sets up the structure for JSON:API responses. ```ruby # app/serializers/article_serializer.rb class ArticleSerializer include JSONAPI::Serializer attributes :title, :body, :status, :created_at attribute :word_count do |article| article.body.split.size end belongs_to :author has_many :comments end # In controller def show render json: ArticleSerializer.new(@article).serializable_hash end ``` -------------------------------- ### Multi-Environment Configuration for Mission Control Routes Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md Provides a flexible routing configuration for Mission Control Jobs that adapts to different Rails environments (production, staging, development). It allows for distinct authentication strategies per environment. ```ruby # config/routes.rb Rails.application.routes.draw do case Rails.env when "production" # Production: Require admin user authenticate :user, ->(user) { user.admin? } do mount MissionControl::Jobs::Engine, at: "/jobs" end when "staging" # Staging: HTTP Basic Auth constraints(->(req) { authenticate_basic(req) }) do mount MissionControl::Jobs::Engine, at: "/jobs" end else # Development: Open access mount MissionControl::Jobs::Engine, at: "/jobs" end end ``` -------------------------------- ### Add Example to Rswag Response Schema (Ruby) Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-api-controllers/references/api-documentation.md Illustrates how to include an example payload within a response schema definition in Rswag. This helps users understand the expected structure and data of a successful API response. ```ruby response '200', 'success' do schema type: :object, properties: { name: { type: :string } }, example: { name: 'John Doe' } run_test! end ``` -------------------------------- ### IP Whitelist Authentication for Mission Control Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md Implements IP whitelisting for Mission Control Jobs access, restricting access to specified internal IP addresses. The allowed IPs are configured via the `MISSION_CONTROL_IPS` environment variable. ```ruby # config/routes.rb Rails.application.routes.draw do constraints(->(req) { internal_ip?(req.remote_ip) }) do mount MissionControl::Jobs::Engine, at: "/jobs" end end # config/application.rb def internal_ip?(ip) allowed_ips = ENV.fetch('MISSION_CONTROL_IPS', '').split(',') allowed_ips.include?(ip) || ip.start_with?('10.', '192.168.') end ``` -------------------------------- ### Skill Frontmatter Example (YAML) Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/CLAUDE.md Shows the YAML frontmatter structure for a SKILL.md file, defining metadata like name, description, version, and tags. ```yaml --- name: skill-name description: Brief description version: 1.0.0 tags: [tag1, tag2] --- ``` -------------------------------- ### Custom Authentication Logic for Mission Control Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md Sets up custom authentication logic for Mission Control Jobs, allowing access based on specific user attributes or conditions defined in the User model's `can_access_mission_control?` method. ```ruby # config/routes.rb Rails.application.routes.draw do authenticate :user, ->(user) { user.can_access_mission_control? } do mount MissionControl::Jobs::Engine, at: "/jobs" end end # app/models/user.rb class User < ApplicationRecord def can_access_mission_control? admin? || role == "operations" || email.end_with?("@yourcompany.com") end end ``` -------------------------------- ### Monitor Specific Queue Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md This Ruby code snippet shows how to monitor the number of pending and failed jobs for a specific queue (e.g., 'mailers') using the Rails console. This is helpful for identifying bottlenecks or issues within particular queues. ```ruby # Rails console SolidQueue::Job.where(queue_name: "mailers").pending.count SolidQueue::Job.where(queue_name: "mailers").failed.count ``` -------------------------------- ### Project Settings for Fullstack Preset Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/README.md Example of the `.claude/settings.local.json` file for the fullstack preset, configuring skills, agents, and model. ```json { "skills": { "autoLoad": true, "path": ".claude/skills" }, "agents": { "path": ".claude/agents", "default": "fullstack-dev" }, "model": "sonnet", "project": "MyRailsApp", "rails_version": "7.1.3" } ``` -------------------------------- ### Mount Mission Control Jobs Engine at a Custom Route in Rails Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md Demonstrates how to mount the Mission Control Jobs engine at a custom URL path in the Rails application's routes. This allows for flexibility in how the job dashboard is accessed. ```ruby # config/routes.rb mount MissionControl::Jobs::Engine, at: "/admin/background-jobs" ``` -------------------------------- ### Running Rails Tests with Coverage and Viewing Report Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/minitest-testing/references/examples.md Provides bash commands to run Rails tests with code coverage enabled and to open the generated coverage report in a web browser. ```bash # Run tests with coverage COVERAGE=true bin/rails test # View coverage report open coverage/index.html ``` -------------------------------- ### Traefik Configuration for SSL and Routing (YAML) Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-deployment/references/examples.md Configures Traefik to handle SSL certificates and HTTP to HTTPS redirection. It specifies ports, volumes for Let's Encrypt certificates, and routing rules. This setup ensures secure communication and proper traffic management. ```yaml # config/deploy.yml traefik: options: publish: - 443:443 - 80:80 volume: - "/letsencrypt:/letsencrypt" args: entryPoints.web.address: ":80" entryPoints.web.http.redirections.entryPoint.to: websecure entryPoints.web.http.redirections.entryPoint.scheme: https entryPoints.websecure.address: ":443" certificatesResolvers.letsencrypt.acme.email: "admin@example.com" certificatesResolvers.letsencrypt.acme.storage: "/letsencrypt/acme.json" certificatesResolvers.letsencrypt.acme.httpchallenge: true certificatesResolvers.letsencrypt.acme.httpchallenge.entrypoint: web servers: web: labels: traefik.http.routers.myapp-secure.tls.certresolver: letsencrypt ``` -------------------------------- ### Filter Sensitive Parameters in Rails Source: https://github.com/shoebtamboli/rails_claude_skills/blob/main/lib/generators/claude/skills_library/rails-jobs/MISSION_CONTROL_SETUP.md This Ruby code snippet configures Rails to filter sensitive parameters from logs. It lists parameters like passwords, tokens, and secrets that should be redacted to enhance security. This is typically placed in the `application.rb` or `production.rb` initializer. ```ruby config.filter_parameters = [:password, :token, :secret, :api_key] ```