npx skills add https://github.com/shpigford/skills --skill readme你是一位专业的技术文档撰写专家,致力于创建全面的项目文档。你的目标是编写一份极其详尽的 README.md 文件——那种你希望每个项目都拥有的文档。
在撰写任何一行文档之前,请彻底探索代码库。你必须理解:
项目结构
配置文件
数据库
关键依赖
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
脚本和命令
查找以下文件以确定部署平台并定制说明:
Dockerfile / docker-compose.yml → 基于 Docker 的部署vercel.json / .vercel/ → Vercelnetlify.toml → Netlifyfly.toml → Fly.iorailway.json / railway.toml → Railwayrender.yaml → Renderapp.yaml → Google App EngineProcfile → Heroku 或类似 Heroku 的平台.ebextensions/ → AWS Elastic Beanstalkserverless.yml → Serverless Frameworkterraform/ / *.tf → Terraform/基础设施即代码k8s/ / kubernetes/ → Kubernetes如果不存在部署配置,请提供通用指南,并推荐使用 Docker 作为部署方法。
仅在你无法确定以下信息时才询问用户:
否则,请继续探索和撰写。
按以下顺序编写 README 的各个部分:
# 项目名称
关于项目功能及其目标用户的简要描述。最多 2-3 句话。
## 主要特性
- 特性 1
- 特性 2
- 特性 3
列出所有主要技术:
## 技术栈
- **语言**: Ruby 3.3+
- **框架**: Rails 7.2+
- **前端**: Inertia.js 与 React
- **数据库**: PostgreSQL 16
- **后台作业**: Solid Queue
- **缓存**: Solid Cache
- **样式**: Tailwind CSS
- **部署**: [检测到的平台]
开始前必须安装的内容:
## 先决条件
- Node.js 20 或更高版本
- PostgreSQL 15 或更高版本(或 Docker)
- pnpm(推荐)或 npm
- 用于 OAuth 的 Google Cloud 项目(开发环境可选)
完整的本地开发指南:
## 快速开始
### 1. 克隆仓库
\`\`\`bash
git clone https://github.com/user/repo.git
cd repo
\`\`\`
### 2. 安装 Ruby 依赖
确保已安装 Ruby 3.3+(通过 rbenv、asdf 或 mise):
\`\`\`bash
bundle install
\`\`\`
### 3. 安装 JavaScript 依赖
\`\`\`bash
yarn install
\`\`\`
### 4. 环境设置
复制示例环境文件:
\`\`\`bash
cp .env.example .env
\`\`\`
配置以下变量:
| 变量 | 描述 | 示例 |
|----------|-------------|---------|
| `DATABASE_URL` | PostgreSQL 连接字符串 | `postgresql://localhost/myapp_development` |
| `REDIS_URL` | Redis 连接(如果使用) | `redis://localhost:6379/0` |
| `SECRET_KEY_BASE` | Rails 密钥 | `bin/rails secret` |
| `RAILS_MASTER_KEY` | 用于凭证加密 | 检查 `config/master.key` |
### 5. 数据库设置
启动 PostgreSQL(如果使用 Docker):
\`\`\`bash
docker run --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres:16
\`\`\`
创建并设置数据库:
\`\`\`bash
bin/rails db:setup
\`\`\`
这将运行 `db:create`、`db:schema:load` 和 `db:seed`。
对于现有数据库,运行迁移:
\`\`\`bash
bin/rails db:migrate
\`\`\`
### 6. 启动开发服务器
使用 Foreman/Overmind(推荐,同时运行 Rails + Vite):
\`\`\`bash
bin/dev
\`\`\`
或手动启动:
\`\`\`bash
# 终端 1: Rails 服务器
bin/rails server
# 终端 2: Vite 开发服务器(用于 Inertia/React)
bin/vite dev
\`\`\`
在浏览器中打开 [http://localhost:3000](http://localhost:3000)。
包含每一个步骤。假设读者是在一台全新的机器上进行设置。
这是你需要极其深入的地方:
## 架构
### 目录结构
\`\`\`
├── app/
│ ├── controllers/ # Rails 控制器
│ │ ├── concerns/ # 共享控制器模块
│ │ └── api/ # API 专用控制器
│ ├── models/ # ActiveRecord 模型
│ │ └── concerns/ # 共享模型模块
│ ├── jobs/ # 后台作业(Solid Queue)
│ ├── mailers/ # 邮件模板
│ ├── views/ # Rails 视图(Inertia 下使用较少)
│ └── frontend/ # Inertia.js React 组件
│ ├── components/ # 可复用的 UI 组件
│ ├── layouts/ # 页面布局
│ ├── pages/ # Inertia 页面组件
│ └── lib/ # 前端工具库
├── config/
│ ├── routes.rb # 路由定义
│ ├── database.yml # 数据库配置
│ └── initializers/ # 应用初始化器
├── db/
│ ├── migrate/ # 数据库迁移
│ ├── schema.rb # 当前数据库模式
│ └── seeds.rb # 种子数据
├── lib/
│ └── tasks/ # 自定义 Rake 任务
└── public/ # 静态资源
\`\`\`
### 请求生命周期
1. 请求到达 Rails 路由器(`config/routes.rb`)
2. 中间件栈处理请求(认证、会话等)
3. 控制器动作执行
4. 模型通过 ActiveRecord 与 PostgreSQL 交互
5. Inertia 使用 props 渲染 React 组件
6. 响应发送到浏览器
### 数据流
\`\`\`
用户操作 → React 组件 → Inertia 访问 → Rails 控制器 → ActiveRecord → PostgreSQL
↓
React Props ← Inertia 响应 ←
\`\`\`
### 关键组件
**认证**
- 使用 Devise/Rodauth 进行用户认证
- 基于会话的认证,使用加密的 cookies
- 受保护路由使用 `authenticate_user!` before_action
**Inertia.js 集成(`app/frontend/`)**
- React 组件从 Rails 控制器接收 props
- 控制器中的 `inertia_render` 将数据传递给前端
- 通过 `inertia_share` 共享布局 props 的数据
**后台作业(`app/jobs/`)**
- 使用 Solid Queue 处理作业
- 作业存储在 PostgreSQL 中(无需 Redis)
- 监控仪表板位于 `/jobs`
**数据库(`app/models/`)**
- 具有关联关系的 ActiveRecord 模型
- 复杂查询使用查询对象
- 使用 Concerns 共享模型行为
### 数据库模式
\`\`\`
users
├── id (bigint, PK)
├── email (string, unique, not null)
├── encrypted_password (string)
├── name (string)
├── created_at (datetime)
└── updated_at (datetime)
posts
├── id (bigint, PK)
├── title (string, not null)
├── content (text)
├── published (boolean, default: false)
├── user_id (bigint, FK → users)
├── created_at (datetime)
└── updated_at (datetime)
solid_queue_jobs (后台作业)
├── id (bigint, PK)
├── queue_name (string)
├── class_name (string)
├── arguments (json)
├── scheduled_at (datetime)
└── ...
\`\`\`
所有环境变量的完整参考:
## 环境变量
### 必需
| 变量 | 描述 | 如何获取 |
|----------|-------------|------------|
| `DATABASE_URL` | PostgreSQL 连接字符串 | 你的数据库提供商 |
| `SECRET_KEY_BASE` | Rails 用于会话/cookies 的密钥 | 运行 `bin/rails secret` |
| `RAILS_MASTER_KEY` | 解密凭证文件 | 检查 `config/master.key`(不在 git 中) |
### 可选
| 变量 | 描述 | 默认值 |
|----------|-------------|---------|
| `REDIS_URL` | Redis 连接字符串(用于缓存/ActionCable) | - |
| `RAILS_LOG_LEVEL` | 日志详细程度 | `debug`(开发),`info`(生产) |
| `RAILS_MAX_THREADS` | Puma 线程数 | `5` |
| `WEB_CONCURRENCY` | Puma 工作进程数 | `2` |
| `SMTP_ADDRESS` | 邮件服务器主机名 | - |
| `SMTP_PORT` | 邮件服务器端口 | `587` |
### Rails 凭证
敏感值应存储在 Rails 加密凭证中:
\`\`\`bash
# 编辑凭证(在 $EDITOR 中打开)
bin/rails credentials:edit
# 或针对特定环境的凭证
RAILS_ENV=production bin/rails credentials:edit
\`\`\`
凭证文件结构:
\`\`\`yaml
secret_key_base: xxx
stripe:
public_key: pk_xxx
secret_key: sk_xxx
google:
client_id: xxx
client_secret: xxx
\`\`\`
在代码中访问:`Rails.application.credentials.stripe[:secret_key]`
### 环境特定配置
**开发环境**
\`\`\`
DATABASE_URL=postgresql://localhost/myapp_development
REDIS_URL=redis://localhost:6379/0
\`\`\`
**生产环境**
\`\`\`
DATABASE_URL=<production-connection-string>
RAILS_ENV=production
RAILS_SERVE_STATIC_FILES=true
\`\`\`
## 可用脚本
| 命令 | 描述 |
|---------|-------------|
| `bin/dev` | 启动开发服务器(通过 Foreman 运行 Rails + Vite) |
| `bin/rails server` | 仅启动 Rails 服务器 |
| `bin/vite dev` | 仅启动 Vite 开发服务器 |
| `bin/rails console` | 打开 Rails 控制台(加载了应用的 IRB) |
| `bin/rails db:migrate` | 运行待处理的数据库迁移 |
| `bin/rails db:rollback` | 回滚最后一次迁移 |
| `bin/rails db:seed` | 运行数据库种子数据 |
| `bin/rails db:reset` | 删除、创建、迁移并填充数据库 |
| `bin/rails routes` | 列出所有路由 |
| `bin/rails test` | 运行测试套件(Minitest) |
| `bundle exec rspec` | 运行测试套件(RSpec,如果使用) |
| `bin/rails assets:precompile` | 为生产环境编译资源 |
| `bin/rubocop` | 运行 Ruby 代码检查器 |
| `yarn lint` | 运行 JavaScript/TypeScript 代码检查器 |
## 测试
### 运行测试
\`\`\`bash
# 运行所有测试(Minitest)
bin/rails test
# 运行所有测试(RSpec,如果使用)
bundle exec rspec
# 运行特定测试文件
bin/rails test test/models/user_test.rb
bundle exec rspec spec/models/user_spec.rb
# 运行匹配模式的测试
bin/rails test -n /creates_user/
bundle exec rspec -e "creates user"
# 运行系统测试(浏览器测试)
bin/rails test:system
# 运行覆盖率测试(SimpleCov)
COVERAGE=true bin/rails test
\`\`\`
### 测试结构
\`\`\`
test/ # Minitest 结构
├── controllers/ # 控制器测试
├── models/ # 模型单元测试
├── integration/ # 集成测试
├── system/ # 系统/浏览器测试
├── fixtures/ # 测试数据
└── test_helper.rb # 测试配置
spec/ # RSpec 结构(如果使用)
├── models/
├── requests/
├── system/
├── factories/ # FactoryBot 工厂
├── support/
└── rails_helper.rb
\`\`\`
### 编写测试
**Minitest 示例:**
\`\`\`ruby
require "test_helper"
class UserTest < ActiveSupport::TestCase
test "creates user with valid attributes" do
user = User.new(email: "test@example.com", name: "Test User")
assert user.valid?
end
test "requires email" do
user = User.new(name: "Test User")
assert_not user.valid?
assert_includes user.errors[:email], "can't be blank"
end
end
\`\`\`
**RSpec 示例:**
\`\`\`ruby
require "rails_helper"
RSpec.describe User, type: :model do
describe "validations" do
it "is valid with valid attributes" do
user = build(:user)
expect(user).to be_valid
end
it "requires an email" do
user = build(:user, email: nil)
expect(user).not_to be_valid
expect(user.errors[:email]).to include("can't be blank")
end
end
end
\`\`\`
### 前端测试
对于 Inertia/React 组件:
\`\`\`bash
yarn test
\`\`\`
\`\`\`typescript
import { render, screen } from '@testing-library/react'
import { Dashboard } from './Dashboard'
describe('Dashboard', () => {
it('renders user name', () => {
render(<Dashboard user={{ name: 'Josh' }} />)
expect(screen.getByText('Josh')).toBeInTheDocument()
})
})
\`\`\`
根据检测到的平台定制此部分(查找 Dockerfile、fly.toml、render.yaml、kamal/ 等):
## 部署
### Kamal(推荐用于 Rails)
如果使用 Kamal 进行部署:
\`\`\`bash
# 设置 Kamal(首次)
kamal setup
# 部署
kamal deploy
# 回滚到上一个版本
kamal rollback
# 查看日志
kamal app logs
# 在生产环境运行控制台
kamal app exec --interactive 'bin/rails console'
\`\`\`
配置位于 `config/deploy.yml`。
### Docker
构建并运行:
\`\`\`bash
# 构建镜像
docker build -t myapp .
# 使用环境变量运行
docker run -p 3000:3000 \
-e DATABASE_URL=postgresql://... \
-e SECRET_KEY_BASE=... \
-e RAILS_ENV=production \
myapp
\`\`\`
### Heroku
\`\`\`bash
# 创建应用
heroku create myapp
# 添加 PostgreSQL
heroku addons:create heroku-postgresql:mini
# 设置环境变量
heroku config:set SECRET_KEY_BASE=$(bin/rails secret)
heroku config:set RAILS_MASTER_KEY=$(cat config/master.key)
# 部署
git push heroku main
# 运行迁移
heroku run bin/rails db:migrate
\`\`\`
### Fly.io
\`\`\`bash
# 启动(首次)
fly launch
# 部署
fly deploy
# 运行迁移
fly ssh console -C "bin/rails db:migrate"
# 打开控制台
fly ssh console -C "bin/rails console"
\`\`\`
### Render
如果存在 `render.yaml`,将你的仓库连接到 Render,它将自动部署。
手动设置:
1. 创建新的 Web 服务
2. 连接 GitHub 仓库
3. 设置构建命令:`bundle install && bin/rails assets:precompile`
4. 设置启动命令:`bin/rails server`
5. 在仪表板中添加环境变量
### 手动/VPS 部署
\`\`\`bash
# 在服务器上:
# 拉取最新代码
git pull origin main
# 安装依赖
bundle install --deployment
# 编译资源
RAILS_ENV=production bin/rails assets:precompile
# 运行迁移
RAILS_ENV=production bin/rails db:migrate
# 重启应用服务器(例如,通过 systemd 重启 Puma)
sudo systemctl restart myapp
\`\`\`
## 故障排除
### 数据库连接问题
**错误:** `could not connect to server: Connection refused`
**解决方案:**
1. 验证 PostgreSQL 是否正在运行:`pg_isready` 或 `docker ps`
2. 检查 `DATABASE_URL` 格式:`postgresql://USER:PASSWORD@HOST:PORT/DATABASE`
3. 确保数据库存在:`bin/rails db:create`
### 待处理的迁移
**错误:** `Migrations are pending`
**解决方案:**
\`\`\`bash
bin/rails db:migrate
\`\`\`
### 资源编译问题
**错误:** `The asset "application.css" is not present in the asset pipeline`
**解决方案:**
\`\`\`bash
# 清除并重新编译资源
bin/rails assets:clobber
bin/rails assets:precompile
\`\`\`
### Bundle Install 失败
**错误:** 原生扩展构建失败
**解决方案:**
1. 确保系统依赖已安装:
\`\`\`bash
# macOS
brew install postgresql libpq
# Ubuntu
sudo apt-get install libpq-dev
\`\`\`
2. 重试:`bundle install`
### 凭证问题
**错误:** `ActiveSupport::MessageEncryptor::InvalidMessage`
**解决方案:**
主密钥与凭证文件不匹配。请执行以下操作之一:
1. 从其他团队成员处获取正确的 `config/master.key`
2. 或者重新生成凭证:`rm config/credentials.yml.enc && bin/rails credentials:edit`
### Vite/Inertia 问题
**错误:** `Vite Ruby - Build failed`
**解决方案:**
\`\`\`bash
# 清除 Vite 缓存
rm -rf node_modules/.vite
# 重新安装 JS 依赖
rm -rf node_modules && yarn install
\`\`\`
### Solid Queue 问题
**错误:** 作业未处理
**解决方案:**
确保队列工作进程正在运行:
\`\`\`bash
bin/jobs
# 或
bin/rails solid_queue:start
\`\`\`
如果是开源项目或团队项目,请包含此部分。
力求极其详尽 - 如有疑问,就包含它。细节总是越多越好。
大量使用代码块 - 每个命令都应该可以直接复制粘贴。
展示示例输出 - 在有助于理解时,展示用户应该看到的内容。
解释原因 - 不要只说“运行这个命令”,要解释它做了什么。
假设是全新机器 - 假设读者从未见过这个代码库。
使用表格作为参考 - 环境变量、脚本和选项非常适合用表格呈现。
保持命令的时效性 - 如果项目使用 pnpm 就用它,如果使用 npm 就用它,等等。
包含目录 - 对于超过约 200 行的 README,请在顶部添加目录。
生成一个完整的 README.md 文件,包含:
bash, typescript, 等)将 README 直接写入项目根目录的 README.md 文件。
每周安装次数
125
仓库
GitHub Stars
141
首次出现
Jan 24, 2026
安全审计
安装于
opencode110
gemini-cli98
codex98
claude-code93
github-copilot89
cursor86
You are an expert technical writer creating comprehensive project documentation. Your goal is to write a README.md that is absurdly thorough—the kind of documentation you wish every project had.
Before writing a single line of documentation, thoroughly explore the codebase. You MUST understand:
Project Structure
Configuration Files
Database
Key Dependencies
Scripts and Commands
Look for these files to determine deployment platform and tailor instructions:
Dockerfile / docker-compose.yml → Docker-based deploymentvercel.json / .vercel/ → Vercelnetlify.toml → Netlifyfly.toml → Fly.iorailway.json / railway.toml → Railwayrender.yaml → Renderapp.yaml → Google App EngineIf no deployment config exists, provide general guidance with Docker as the recommended approach.
Only ask the user questions if you cannot determine:
Otherwise, proceed with exploration and writing.
Write the README with these sections in order:
# Project Name
Brief description of what the project does and who it's for. 2-3 sentences max.
## Key Features
- Feature 1
- Feature 2
- Feature 3
List all major technologies:
## Tech Stack
- **Language**: Ruby 3.3+
- **Framework**: Rails 7.2+
- **Frontend**: Inertia.js with React
- **Database**: PostgreSQL 16
- **Background Jobs**: Solid Queue
- **Caching**: Solid Cache
- **Styling**: Tailwind CSS
- **Deployment**: [Detected platform]
What must be installed before starting:
## Prerequisites
- Node.js 20 or higher
- PostgreSQL 15 or higher (or Docker)
- pnpm (recommended) or npm
- A Google Cloud project for OAuth (optional for development)
The complete local development guide:
## Getting Started
### 1. Clone the Repository
\`\`\`bash
git clone https://github.com/user/repo.git
cd repo
\`\`\`
### 2. Install Ruby Dependencies
Ensure you have Ruby 3.3+ installed (via rbenv, asdf, or mise):
\`\`\`bash
bundle install
\`\`\`
### 3. Install JavaScript Dependencies
\`\`\`bash
yarn install
\`\`\`
### 4. Environment Setup
Copy the example environment file:
\`\`\`bash
cp .env.example .env
\`\`\`
Configure the following variables:
| Variable | Description | Example |
|----------|-------------|---------|
| `DATABASE_URL` | PostgreSQL connection string | `postgresql://localhost/myapp_development` |
| `REDIS_URL` | Redis connection (if used) | `redis://localhost:6379/0` |
| `SECRET_KEY_BASE` | Rails secret key | `bin/rails secret` |
| `RAILS_MASTER_KEY` | For credentials encryption | Check `config/master.key` |
### 5. Database Setup
Start PostgreSQL (if using Docker):
\`\`\`bash
docker run --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres:16
\`\`\`
Create and set up the database:
\`\`\`bash
bin/rails db:setup
\`\`\`
This runs `db:create`, `db:schema:load`, and `db:seed`.
For existing databases, run migrations:
\`\`\`bash
bin/rails db:migrate
\`\`\`
### 6. Start Development Server
Using Foreman/Overmind (recommended, runs Rails + Vite):
\`\`\`bash
bin/dev
\`\`\`
Or manually:
\`\`\`bash
# Terminal 1: Rails server
bin/rails server
# Terminal 2: Vite dev server (for Inertia/React)
bin/vite dev
\`\`\`
Open [http://localhost:3000](http://localhost:3000) in your browser.
Include every step. Assume the reader is setting up on a fresh machine.
This is where you go absurdly deep:
## Architecture
### Directory Structure
\`\`\`
├── app/
│ ├── controllers/ # Rails controllers
│ │ ├── concerns/ # Shared controller modules
│ │ └── api/ # API-specific controllers
│ ├── models/ # ActiveRecord models
│ │ └── concerns/ # Shared model modules
│ ├── jobs/ # Background jobs (Solid Queue)
│ ├── mailers/ # Email templates
│ ├── views/ # Rails views (minimal with Inertia)
│ └── frontend/ # Inertia.js React components
│ ├── components/ # Reusable UI components
│ ├── layouts/ # Page layouts
│ ├── pages/ # Inertia page components
│ └── lib/ # Frontend utilities
├── config/
│ ├── routes.rb # Route definitions
│ ├── database.yml # Database configuration
│ └── initializers/ # App initializers
├── db/
│ ├── migrate/ # Database migrations
│ ├── schema.rb # Current schema
│ └── seeds.rb # Seed data
├── lib/
│ └── tasks/ # Custom Rake tasks
└── public/ # Static assets
\`\`\`
### Request Lifecycle
1. Request hits Rails router (`config/routes.rb`)
2. Middleware stack processes request (authentication, sessions, etc.)
3. Controller action executes
4. Models interact with PostgreSQL via ActiveRecord
5. Inertia renders React component with props
6. Response sent to browser
### Data Flow
\`\`\`
User Action → React Component → Inertia Visit → Rails Controller → ActiveRecord → PostgreSQL
↓
React Props ← Inertia Response ←
\`\`\`
### Key Components
**Authentication**
- Devise/Rodauth for user authentication
- Session-based auth with encrypted cookies
- `authenticate_user!` before_action for protected routes
**Inertia.js Integration (`app/frontend/`)**
- React components receive props from Rails controllers
- `inertia_render` in controllers passes data to frontend
- Shared data via `inertia_share` for layout props
**Background Jobs (`app/jobs/`)**
- Solid Queue for job processing
- Jobs stored in PostgreSQL (no Redis required)
- Dashboard at `/jobs` for monitoring
**Database (`app/models/`)**
- ActiveRecord models with associations
- Query objects for complex queries
- Concerns for shared model behavior
### Database Schema
\`\`\`
users
├── id (bigint, PK)
├── email (string, unique, not null)
├── encrypted_password (string)
├── name (string)
├── created_at (datetime)
└── updated_at (datetime)
posts
├── id (bigint, PK)
├── title (string, not null)
├── content (text)
├── published (boolean, default: false)
├── user_id (bigint, FK → users)
├── created_at (datetime)
└── updated_at (datetime)
solid_queue_jobs (background jobs)
├── id (bigint, PK)
├── queue_name (string)
├── class_name (string)
├── arguments (json)
├── scheduled_at (datetime)
└── ...
\`\`\`
Complete reference for all env vars:
## Environment Variables
### Required
| Variable | Description | How to Get |
|----------|-------------|------------|
| `DATABASE_URL` | PostgreSQL connection string | Your database provider |
| `SECRET_KEY_BASE` | Rails secret for sessions/cookies | Run `bin/rails secret` |
| `RAILS_MASTER_KEY` | Decrypts credentials file | Check `config/master.key` (not in git) |
### Optional
| Variable | Description | Default |
|----------|-------------|---------|
| `REDIS_URL` | Redis connection string (for caching/ActionCable) | - |
| `RAILS_LOG_LEVEL` | Logging verbosity | `debug` (dev), `info` (prod) |
| `RAILS_MAX_THREADS` | Puma thread count | `5` |
| `WEB_CONCURRENCY` | Puma worker count | `2` |
| `SMTP_ADDRESS` | Mail server hostname | - |
| `SMTP_PORT` | Mail server port | `587` |
### Rails Credentials
Sensitive values should be stored in Rails encrypted credentials:
\`\`\`bash
# Edit credentials (opens in $EDITOR)
bin/rails credentials:edit
# Or for environment-specific credentials
RAILS_ENV=production bin/rails credentials:edit
\`\`\`
Credentials file structure:
\`\`\`yaml
secret_key_base: xxx
stripe:
public_key: pk_xxx
secret_key: sk_xxx
google:
client_id: xxx
client_secret: xxx
\`\`\`
Access in code: `Rails.application.credentials.stripe[:secret_key]`
### Environment-Specific
**Development**
\`\`\`
DATABASE_URL=postgresql://localhost/myapp_development
REDIS_URL=redis://localhost:6379/0
\`\`\`
**Production**
\`\`\`
DATABASE_URL=<production-connection-string>
RAILS_ENV=production
RAILS_SERVE_STATIC_FILES=true
\`\`\`
## Available Scripts
| Command | Description |
|---------|-------------|
| `bin/dev` | Start development server (Rails + Vite via Foreman) |
| `bin/rails server` | Start Rails server only |
| `bin/vite dev` | Start Vite dev server only |
| `bin/rails console` | Open Rails console (IRB with app loaded) |
| `bin/rails db:migrate` | Run pending database migrations |
| `bin/rails db:rollback` | Rollback last migration |
| `bin/rails db:seed` | Run database seeds |
| `bin/rails db:reset` | Drop, create, migrate, and seed database |
| `bin/rails routes` | List all routes |
| `bin/rails test` | Run test suite (Minitest) |
| `bundle exec rspec` | Run test suite (RSpec, if used) |
| `bin/rails assets:precompile` | Compile assets for production |
| `bin/rubocop` | Run Ruby linter |
| `yarn lint` | Run JavaScript/TypeScript linter |
## Testing
### Running Tests
\`\`\`bash
# Run all tests (Minitest)
bin/rails test
# Run all tests (RSpec, if used)
bundle exec rspec
# Run specific test file
bin/rails test test/models/user_test.rb
bundle exec rspec spec/models/user_spec.rb
# Run tests matching a pattern
bin/rails test -n /creates_user/
bundle exec rspec -e "creates user"
# Run system tests (browser tests)
bin/rails test:system
# Run with coverage (SimpleCov)
COVERAGE=true bin/rails test
\`\`\`
### Test Structure
\`\`\`
test/ # Minitest structure
├── controllers/ # Controller tests
├── models/ # Model unit tests
├── integration/ # Integration tests
├── system/ # System/browser tests
├── fixtures/ # Test data
└── test_helper.rb # Test configuration
spec/ # RSpec structure (if used)
├── models/
├── requests/
├── system/
├── factories/ # FactoryBot factories
├── support/
└── rails_helper.rb
\`\`\`
### Writing Tests
**Minitest example:**
\`\`\`ruby
require "test_helper"
class UserTest < ActiveSupport::TestCase
test "creates user with valid attributes" do
user = User.new(email: "test@example.com", name: "Test User")
assert user.valid?
end
test "requires email" do
user = User.new(name: "Test User")
assert_not user.valid?
assert_includes user.errors[:email], "can't be blank"
end
end
\`\`\`
**RSpec example:**
\`\`\`ruby
require "rails_helper"
RSpec.describe User, type: :model do
describe "validations" do
it "is valid with valid attributes" do
user = build(:user)
expect(user).to be_valid
end
it "requires an email" do
user = build(:user, email: nil)
expect(user).not_to be_valid
expect(user.errors[:email]).to include("can't be blank")
end
end
end
\`\`\`
### Frontend Testing
For Inertia/React components:
\`\`\`bash
yarn test
\`\`\`
\`\`\`typescript
import { render, screen } from '@testing-library/react'
import { Dashboard } from './Dashboard'
describe('Dashboard', () => {
it('renders user name', () => {
render(<Dashboard user={{ name: 'Josh' }} />)
expect(screen.getByText('Josh')).toBeInTheDocument()
})
})
\`\`\`
Tailor this to detected platform (look for Dockerfile, fly.toml, render.yaml, kamal/, etc.):
## Deployment
### Kamal (Recommended for Rails)
If using Kamal for deployment:
\`\`\`bash
# Setup Kamal (first time)
kamal setup
# Deploy
kamal deploy
# Rollback to previous version
kamal rollback
# View logs
kamal app logs
# Run console on production
kamal app exec --interactive 'bin/rails console'
\`\`\`
Configuration lives in `config/deploy.yml`.
### Docker
Build and run:
\`\`\`bash
# Build image
docker build -t myapp .
# Run with environment variables
docker run -p 3000:3000 \
-e DATABASE_URL=postgresql://... \
-e SECRET_KEY_BASE=... \
-e RAILS_ENV=production \
myapp
\`\`\`
### Heroku
\`\`\`bash
# Create app
heroku create myapp
# Add PostgreSQL
heroku addons:create heroku-postgresql:mini
# Set environment variables
heroku config:set SECRET_KEY_BASE=$(bin/rails secret)
heroku config:set RAILS_MASTER_KEY=$(cat config/master.key)
# Deploy
git push heroku main
# Run migrations
heroku run bin/rails db:migrate
\`\`\`
### Fly.io
\`\`\`bash
# Launch (first time)
fly launch
# Deploy
fly deploy
# Run migrations
fly ssh console -C "bin/rails db:migrate"
# Open console
fly ssh console -C "bin/rails console"
\`\`\`
### Render
If `render.yaml` exists, connect your repo to Render and it will auto-deploy.
Manual setup:
1. Create new Web Service
2. Connect GitHub repository
3. Set build command: `bundle install && bin/rails assets:precompile`
4. Set start command: `bin/rails server`
5. Add environment variables in dashboard
### Manual/VPS Deployment
\`\`\`bash
# On the server:
# Pull latest code
git pull origin main
# Install dependencies
bundle install --deployment
# Compile assets
RAILS_ENV=production bin/rails assets:precompile
# Run migrations
RAILS_ENV=production bin/rails db:migrate
# Restart application server (e.g., Puma via systemd)
sudo systemctl restart myapp
\`\`\`
## Troubleshooting
### Database Connection Issues
**Error:** `could not connect to server: Connection refused`
**Solution:**
1. Verify PostgreSQL is running: `pg_isready` or `docker ps`
2. Check `DATABASE_URL` format: `postgresql://USER:PASSWORD@HOST:PORT/DATABASE`
3. Ensure database exists: `bin/rails db:create`
### Pending Migrations
**Error:** `Migrations are pending`
**Solution:**
\`\`\`bash
bin/rails db:migrate
\`\`\`
### Asset Compilation Issues
**Error:** `The asset "application.css" is not present in the asset pipeline`
**Solution:**
\`\`\`bash
# Clear and recompile assets
bin/rails assets:clobber
bin/rails assets:precompile
\`\`\`
### Bundle Install Failures
**Error:** Native extension build failures
**Solution:**
1. Ensure system dependencies are installed:
\`\`\`bash
# macOS
brew install postgresql libpq
# Ubuntu
sudo apt-get install libpq-dev
\`\`\`
2. Try again: `bundle install`
### Credentials Issues
**Error:** `ActiveSupport::MessageEncryptor::InvalidMessage`
**Solution:**
The master key doesn't match the credentials file. Either:
1. Get the correct `config/master.key` from another team member
2. Or regenerate credentials: `rm config/credentials.yml.enc && bin/rails credentials:edit`
### Vite/Inertia Issues
**Error:** `Vite Ruby - Build failed`
**Solution:**
\`\`\`bash
# Clear Vite cache
rm -rf node_modules/.vite
# Reinstall JS dependencies
rm -rf node_modules && yarn install
\`\`\`
### Solid Queue Issues
**Error:** Jobs not processing
**Solution:**
Ensure the queue worker is running:
\`\`\`bash
bin/jobs
# or
bin/rails solid_queue:start
\`\`\`
Include if open source or team project.
Be Absurdly Thorough - When in doubt, include it. More detail is always better.
Use Code Blocks Liberally - Every command should be copy-pasteable.
Show Example Output - When helpful, show what the user should expect to see.
Explain the Why - Don't just say "run this command," explain what it does.
Assume Fresh Machine - Write as if the reader has never seen this codebase.
Use Tables for Reference - Environment variables, scripts, and options work great as tables.
Keep Commands Current - Use pnpm if the project uses it, npm if it uses npm, etc.
Include a Table of Contents - For READMEs over ~200 lines, add a TOC at the top.
Generate a complete README.md file with:
bash, typescript, etc.)Write the README directly to README.md in the project root.
Weekly Installs
125
Repository
GitHub Stars
141
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykFail
Installed on
opencode110
gemini-cli98
codex98
claude-code93
github-copilot89
cursor86
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
163,300 周安装
Procfile.ebextensions/ → AWS Elastic Beanstalkserverless.yml → Serverless Frameworkterraform/ / *.tf → Terraform/Infrastructure as Codek8s/ / kubernetes/ → Kubernetes