Alpha 技能
alpha
Alpha 技能
- License 许可
- MIT
- 最近更新
- 2026-11-09
- Stars
- ★ 344
- Forks
- 7
01 前言 Front Matter
- name
- rails-upgrade-4-to-5
- description
- Upgrade a Ruby on Rails app from 4.x to 5.x — dual-boot via next_rails, ApplicationRecord introduction, ActionCable arrival, strong parameters becoming mandatory, params no longer hash-like, the version hop sequence, the Rails 5.1 system tests and `yarn` arrival, the Rails 5.2 ActiveStorage + credentials. Use when upgrading from Rails 4 to 5, the user mentions ApplicationRecord, strong parameters, params.permit, ActionCable, the params HashWithIndifferentAccess change, or asks how to leave Rails 4.
02 资源文件 1
- 参考文档evals.md768 B
03 SKILL.md 正文
Rails 4 → 5 Upgrade
Rails 4.2 → 5.0 is one of the biggest API breaks in the past decade.
paramsstop being a Hash. Strong parameters become mandatory. ApplicationRecord arrives. Treat as a multi-month project for a non-trivial app.
The opinion
Dual-boot with
next_rails. Hop 4.2 → 5.0 → 5.1 → 5.2. Ruby 2.2.2+ for Rails 5.0; Ruby 2.5+ for 5.2. Budget weeks-to-months for a non-trivial app.
The hop sequence
4.2 → 5.0 → 5.1 → 5.2
Core patterns
Pattern 1: 4.2 → 5.0 — the breaking changes
Required code changes:
# Rails 4 — base model inheriting from ActiveRecord::Base
class User < ActiveRecord::Base
end
# Rails 5 — inherit from ApplicationRecord
class User < ApplicationRecord
end
# Generate the new base class
bin/rails generate application_record
params change — biggest gotcha:
# Rails 4 — params was a HashWithIndifferentAccess
params[:user][:email] # worked
params.permit(:foo, :bar) # explicit but not required
User.create(params[:user]) # silently allowed any column
# Rails 5 — params is ActionController::Parameters
params[:user][:email] # works (subclass of Hash)
params.merge(...) # returns Parameters, not Hash
User.create(params[:user]) # raises ForbiddenAttributesError — must permit
Audit every Model.create(params[:foo]) / update(params[:foo]) call. Add permit.
Other 5.0 changes:
- ActionCable arrives (no impact unless you use it).
belongs_tois required by default (optional: trueto opt out).- Test framework default switches;
Rails.testmay need--cleanruns. head :okafter arespond_toblock is no longer needed (slight behavior change).
Pattern 2: 5.0 → 5.1
- yarn arrives for managing JS packages.
- System tests (Capybara wrapper) ship.
form_for/form_tagstart to be deprecated in favor ofform_with.secrets.ymlpartially deprecated (full deprecation in 5.2).
Pattern 3: 5.1 → 5.2
- Active Storage ships (file uploads).
- Encrypted credentials (
config/credentials.yml.enc) replacesecrets.yml. Date.currentrecommended overDate.todayfor time-zone safety.
# Migrate secrets.yml → credentials
EDITOR=vim bin/rails credentials:edit
# Paste secrets.yml contents into the encrypted file
Pattern 4: belongs_to required
# Rails 4 — nil author was allowed silently
class Post < ApplicationRecord
belongs_to :author
end
# Rails 5 — validation fires on save if author is nil
# Either fix the data or opt out:
belongs_to :author, optional: true
Audit every belongs_to for optional: true cases.
Common mistakes to refuse
- Don't skip 5.0 (the Parameters change has to land cleanly).
- Don't allow
Model.create(params[:foo])in 5.0+; permit everything. - Don't migrate ActionCable + ApplicationRecord + secrets.yml in the same PR.
See also
rails-upgrade-3-to-4— previous hoprails-upgrade-5-to-6— next hop
Sources
04 同仓库更多 Skills
PromptScript 脚本编写与排查
promptscript
PromptScript 语言专家,用于读取、编写、修改和排查 .prs 文件。适用于处理 PromptScript 语法、创建或编辑 .prs 文件、添加 @identity、@standards、@restrictions、@shortcuts、@skills 或 @agents 等块、配置 promptscript.yaml、解决编译错误、理解继承(@inherit)、组合(@use、@extend、@override)、上下文 @header 元数据,或将 AI 指令迁移到 PromptScript。当用户询问 50 个内置编码智能体编译目标(包括 GitHub Copilot、Claude Code、Cursor、Antigravity、Factory AI 以及基于 AGENTS.md 的平台),或询问用于应用提示词的 bundle 和 prompt-text 目标时,也适用此技能。
基础专家技能
expert
基础专家技能。
测试驱动开发工作流
tdd-workflow
测试驱动开发(TDD)工作流。
PDF 文件处理
pdf-processing
提取 PDF 文本、填写表单、合并文件。用于处理 PDF 时。
React 组件编写规范
react-component-patterns
在此代码库中编写 React 组件的约定。
应用部署发布
deploy-app
将应用部署到预发布(staging)或生产环境。用于部署代码,或当用户提到部署、发布或环境时。