dhh-rails-style by everyinc/compound-engineering-plugin
npx skills add https://github.com/everyinc/compound-engineering-plugin --skill dhh-rails-style<essential_principles>
"最好的代码是你无需编写的代码。次好的代码是那些明显正确的代码。"
原生 Rails 已足够强大:
他们刻意避免使用:
开发理念:
</essential_principles>
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
请指定一个数字或描述您的任务。
| 响应 | 参考阅读 |
|---|---|
| 1, controller | controllers.md |
| 2, model | models.md |
| 3, view, frontend, turbo, stimulus, css | frontend.md |
| 4, architecture, routing, auth, job, cache | architecture.md |
| 5, test, testing, minitest, fixture | testing.md |
| 6, gem, dependency, library | gems.md |
| 7, review | 阅读所有参考资料,然后审查代码 |
| 8, general task | 根据上下文阅读相关参考资料 |
阅读相关参考资料后,将模式应用到用户的代码中。
<quick_reference>
动词: card.close, card.gild, board.publish(而非 set_style 方法)
谓词: card.closed?, card.golden?(根据相关记录的存在性派生)
Concerns: 描述能力的形容词(Closeable, Publishable, Watchable)
控制器: 与资源匹配的名词(Cards::ClosuresController)
作用域:
chronologically, reverse_chronologically, alphabetically, latestpreloaded(标准的预加载名称)indexed_by, sorted_by(参数化)active, unassigned(业务术语,而非 SQL 风格)创建新的资源,而非自定义动作:
POST /cards/:id/close → POST /cards/:id/closure
DELETE /cards/:id/close → DELETE /cards/:id/closure
POST /cards/:id/archive → POST /cards/:id/archival
# 方括号内带空格的符号数组
before_action :set_message, only: %i[ show edit update destroy ]
# 私有方法缩进
private
def set_message
@message = Message.find(params[:id])
end
# 条件判断使用无表达式的 case
case
when params[:before].present?
messages.page_before(params[:before])
else
messages.last_page
end
# 使用感叹号方法进行快速失败
@message = Message.create!(params)
# 简单条件使用三元运算符
@room.direct? ? @room.users : @message.mentionees
状态即记录:
Card.joins(:closure) # 已关闭的卡片
Card.where.missing(:closure) # 未关闭的卡片
当前属性:
belongs_to :creator, default: -> { Current.user }
模型上的授权:
class User < ApplicationRecord
def can_administer?(message)
message.creator == self || admin?
end
end
</quick_reference>
<reference_index>
所有详细模式见 references/:
| 文件 | 主题 |
|---|---|
| controllers.md | REST 映射、concerns、Turbo 响应、API 模式、HTTP 缓存 |
| models.md | Concerns、状态记录、回调、作用域、POROs、授权、广播 |
| frontend.md | Turbo Streams、Stimulus 控制器、CSS layers、OKLCH 颜色、局部模板 |
| architecture.md | 路由、身份验证、作业、Current 属性、缓存、数据库模式 |
| testing.md | Minitest、固件、单元/集成/系统测试、测试模式 |
| gems.md | 他们使用什么 vs 避免什么、决策框架、Gemfile 示例 |
</reference_index>
<success_criteria> 当代码符合以下情况时,即遵循 DHH 风格:
</success_criteria>
重要免责声明:
每周安装次数
367
仓库
GitHub 星标数
10.9K
首次出现
2026年1月20日
安全审计
安装于
opencode323
codex310
gemini-cli308
github-copilot296
cursor280
claude-code279
<essential_principles>
"The best code is the code you don't write. The second best is the code that's obviously correct."
Vanilla Rails is plenty:
What they deliberately avoid:
Development Philosophy:
Specify a number or describe your task.
| Response | Reference to Read |
|---|---|
| 1, controller | controllers.md |
| 2, model | models.md |
| 3, view, frontend, turbo, stimulus, css | frontend.md |
| 4, architecture, routing, auth, job, cache | architecture.md |
| 5, test, testing, minitest, fixture | testing.md |
| 6, gem, dependency, library | gems.md |
| 7, review |
After reading relevant references, apply patterns to the user's code.
<quick_reference>
Verbs: card.close, card.gild, board.publish (not set_style methods)
Predicates: card.closed?, card.golden? (derived from presence of related record)
Concerns: Adjectives describing capability (Closeable, Publishable, Watchable)
Controllers: Nouns matching resources (Cards::ClosuresController)
Scopes:
chronologically, reverse_chronologically, alphabetically, latestpreloaded (standard eager loading name)indexed_by, sorted_by (parameterized)active, unassigned (business terms, not SQL-ish)Instead of custom actions, create new resources:
POST /cards/:id/close → POST /cards/:id/closure
DELETE /cards/:id/close → DELETE /cards/:id/closure
POST /cards/:id/archive → POST /cards/:id/archival
# Symbol arrays with spaces inside brackets
before_action :set_message, only: %i[ show edit update destroy ]
# Private method indentation
private
def set_message
@message = Message.find(params[:id])
end
# Expression-less case for conditionals
case
when params[:before].present?
messages.page_before(params[:before])
else
messages.last_page
end
# Bang methods for fail-fast
@message = Message.create!(params)
# Ternaries for simple conditionals
@room.direct? ? @room.users : @message.mentionees
State as Records:
Card.joins(:closure) # closed cards
Card.where.missing(:closure) # open cards
Current Attributes:
belongs_to :creator, default: -> { Current.user }
Authorization on Models:
class User < ApplicationRecord
def can_administer?(message)
message.creator == self || admin?
end
end
</quick_reference>
<reference_index>
All detailed patterns in references/:
| File | Topics |
|---|---|
| controllers.md | REST mapping, concerns, Turbo responses, API patterns, HTTP caching |
| models.md | Concerns, state records, callbacks, scopes, POROs, authorization, broadcasting |
| frontend.md | Turbo Streams, Stimulus controllers, CSS layers, OKLCH colors, partials |
| architecture.md | Routing, authentication, jobs, Current attributes, caching, database patterns |
| testing.md | Minitest, fixtures, unit/integration/system tests, testing patterns |
| gems.md |
<success_criteria> Code follows DHH style when:
Important Disclaimers:
Weekly Installs
367
Repository
GitHub Stars
10.9K
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode323
codex310
gemini-cli308
github-copilot296
cursor280
claude-code279
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
106,200 周安装
| Read all references, then review code |
| 8, general task | Read relevant references based on context |
| What they use vs avoid, decision framework, Gemfile examples |
| </reference_index> |