alpha
Alpha skill
- 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 language expert for reading, writing, modifying, and troubleshooting .prs files. Use when working with PromptScript syntax, creating or editing .prs files, adding blocks like @identity, @standards, @restrictions, @shortcuts, @skills, or @agents, configuring promptscript.yaml, resolving compilation errors, understanding inheritance (@inherit), composition (@use, @extend, @override), contextual @header metadata, or migrating AI instructions to PromptScript. Also use when asked about the 50 built-in coding agent compilation targets, including GitHub Copilot, Claude Code, Cursor, Antigravity, Factory AI, and AGENTS.md-based platforms, or about the bundle and prompt-text targets for application prompts.
expert
Base expert skill
tdd-workflow
Test-driven development workflow
pdf-processing
Extract PDF text, fill forms, merge files. Use when handling PDFs.
react-component-patterns
Conventions for writing React components in this codebase.
deploy-app
Deploy the application to staging or production environments. Use when deploying code or when the user mentions deployment, releases, or environments.