ombulabs/claude-code_rails-upgrade-skill / rails-upgrade
rails-upgrade
VerifiedAnalyzes Rails applications and generates comprehensive upgrade reports with breaking changes, deprecations, and step-by-step migration guides for Rails 2.3 through 8.1. Use when upgrading Rails applications, planning multi-hop upgrades, querying version-specific changes, or answering what stands between the app and the next Rails version. Based on FastRuby.io methodology and "The Complete Guide to Upgrade Rails" ebook.
version-guides/upgrade-6.0-to-6.1.md
View on GitHub# Rails 6.0 â 6.1 Upgrade Guide
**Ruby Requirement:** 2.5.0+ (2.7+ recommended)
**Based on "The Complete Guide to Upgrade Rails" by FastRuby.io (OmbuLabs)**
---
## Overview
Rails 6.1 introduces:
- **Horizontal database sharding** support
- **Strict loading** to prevent N+1 queries
- **Per-database connection switching**
- **Destroy associations async**
- **Error objects** in Active Model
---
## Breaking Changes
### ðī HIGH PRIORITY
#### update_attributes Removed
**What Changed:**
`update_attributes` and `update_attributes!`, deprecated aliases of `update` and `update!` in 6.0, are removed. Every call raises `NoMethodError`, including calls through `send(:update_attributes, ...)`. There is no patterns file for this hop, so search for them by hand: `grep -rnw update_attributes app lib spec test`, which also finds the `!` form.
**Detection Pattern:**
```ruby
user.update_attributes(name: 'New Name')
user.update_attributes!(name: 'New Name')
```
**Fix:**
```ruby
# BEFORE
user.update_attributes(name: 'New Name')
# AFTER
user.update(name: 'New Name')
```
`update` exists on 6.0 as well, so the rewrite can land before the version bump with no `NextRails.next?` branch.
---
#### config_for Returns HashWithIndifferentAccess
**What Changed:**
`Rails.application.config_for` now returns `ActiveSupport::HashWithIndifferentAccess` instead of `Hash`.
**Detection Pattern:**
```ruby
config = Rails.application.config_for(:some_config)
config.keys.first.class # Was String, now can be accessed as symbol
```
**Fix:**
This is usually transparent, but if you're checking key types explicitly:
```ruby
# BEFORE (may break)
if config.keys.include?("database")
# AFTER (works with both)
if config.key?(:database) || config.key?("database")
```
---
#### respond_to#any Content-Type Change
**What Changed:**
`respond_to#any` now returns `text/html` Content-Type instead of `*/*`.
**Detection Pattern:**
```ruby
respond_to do |format|
format.any { render json: @data }
end
```
**Fix:**
If you need specific Content-Type, use explicit format:
```ruby
# BEFORE
respond_to do |format|
format.any { render json: @data }
end
# AFTER (explicit JSON)
respond_to do |format|
format.json { render json: @data }
format.any { render json: @data, content_type: 'application/json' }
end
```
---
#### HTTPS Redirects Use 308 Status
**What Changed:**
`config.force_ssl` now uses HTTP status 308 instead of 301 for redirects.
**Impact:**
308 preserves the HTTP method (POST stays POST). This is usually correct behavior, but may affect some clients.
**Fix:**
If you need the old 301 behavior:
```ruby
# config/environments/production.rb
config.ssl_options = { redirect: { status: 301 } }
```
---
#### ActiveSupport::Callbacks Default Changed
**What Changed:**
`:unless` and `:if` callbacks now default to `:before` rather than `:after`.
**Detection Pattern:**
```ruby
set_callback :save, :around, :my_callback, if: :condition
```
**Fix:**
Be explicit about callback type:
```ruby
set_callback :save, :around, :my_callback, if: :condition, prepend: true
```
---
### ðĄ MEDIUM PRIORITY
#### ActiveRecord::Base.allow_unsafe_raw_sql Removed
**What Changed:**
The `allow_unsafe_raw_sql` configuration has been removed.
**Detection Pattern:**
```ruby
ActiveRecord::Base.allow_unsafe_raw_sql = :enabled
```
**Fix:**
Remove the configuration. Use `Arel.sql()` for raw SQL:
```ruby
# BEFORE
Model.order("FIELD(id, #{ids.join(',')})")
# AFTER
Model.order(Arel.sql("FIELD(id, #{ids.join(',')})"))
```
---
#### ActiveModel::Errors API Change
**What Changed:**
`ActiveModel::Errors` now returns `Error` objects instead of strings.
**Detection Pattern:**
```ruby
user.errors[:email].first # Was String
user.errors.full_messages # Still works
```
**Fix:**
```ruby
# BEFORE
error_string = user.errors[:email].first
# AFTER
error = user.errors.where(:email).first
error.message # Get the message
error.full_message # Get full message with attribute name
```
---
#### find_or_create_by Behavior Change
**What Changed:**
`find_or_create_by` now handles race conditions better, but behavior changed slightly.
**Detection Pattern:**
```ruby
User.find_or_create_by(email: email)
```
**Fix:**
No changes needed for typical usage. If you relied on specific exception behavior, test thoroughly.
---
## New Features
### Horizontal Database Sharding
```ruby
# database.yml
production:
primary:
database: my_primary
primary_shard_one:
database: my_shard_one
```
### Strict Loading (Prevent N+1)
```ruby
class User < ApplicationRecord
has_many :posts, strict_loading: true
end
# Or at query time
User.strict_loading.includes(:posts).first
```
### Destroy Associations Async
```ruby
class User < ApplicationRecord
has_many :posts, dependent: :destroy_async
end
```
---
## Migration Steps
### Phase 1: Preparation
```bash
git checkout -b rails-61-upgrade
# Set up dual-boot
gem install next_rails
next_rails --init
```
### Phase 2: Gemfile Updates
```ruby
# Gemfile
if next?
gem 'rails', '~> 6.1.0'
else
gem 'rails', '~> 6.0.0'
end
```
### Phase 3: Fix Breaking Changes
1. Replace `update_attributes` / `update_attributes!` with `update` / `update!`
2. Review `config_for` usage
3. Check `respond_to#any` blocks
4. Test SSL redirects if critical
5. Update `ActiveModel::Errors` usage
### Phase 4: Configuration
```bash
rails app:update
```
Update `config/application.rb`:
```ruby
config.load_defaults 6.1
```
### Phase 5: Testing
- Run full test suite
- Test forms with validations
- Test API responses Content-Type
- Verify SSL redirects work correctly
---
## Configuration Migration Checklist
- [ ] Review `config_for` usage for hash access patterns
- [ ] Check `respond_to#any` blocks for Content-Type expectations
- [ ] Test SSL redirect behavior
- [ ] Update `ActiveModel::Errors` usage if accessing errors directly
- [ ] Update `load_defaults` to 6.1
---
## Common Issues â Quick Reference
Error â section lookup for the most common errors encountered during this upgrade:
| Error | See |
|-------|-----|
| `NoMethodError: undefined method 'update_attributes'` | "update_attributes Removed": replace with `update` |
| API client receives `text/html` instead of `application/json` | "respond_to#any Content-Type Change" â `format.json { render json: ... }` |
| SSL redirect loops on POST requests | "HTTPS Redirects Use 308 Status" â `config.ssl_options = { redirect: { status: 301 } }` if the proxy cannot handle 308 |
| `NoMethodError: undefined method 'include?' for #<ActiveModel::Error>` | "ActiveModel::Errors API Change" â `errors.where(:email).map(&:message)` |
---
## Resources
- [Rails 6.1 Release Notes](https://guides.rubyonrails.org/6_1_release_notes.html)
- [RailsDiff 6.0 to 6.1](http://railsdiff.org/6.0.6/6.1.0)
- [Horizontal Sharding Guide](https://guides.rubyonrails.org/active_record_multiple_databases.html)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| planning-and-task-breakdownaddyosmani/agent-skillsBreaks work into ordered tasks. Use when you have a spec or clear requirements and need to break work into implementable tasks. Use when a task feels too large to start, when you need to estimate scope, or when parallel work is possible. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| screenpipethedotmack/claude-memSearch screen and audio history recorded by Screenpipe and optionally save selected context into claude-mem. Use when the user asks to recall desktop activity, a meeting, or something seen in another app through Screenpipe. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| contact-widgetnexu-io/open-designSelf-contained floating chat widget with welcome screen, social links, meeting button, and message input. Single HTML file, zero dependencies. | Stars: 108k | Updated | Claude CodeCodex | Verified | Install |
| meeting-notesnexu-io/open-designMeeting notes page â title bar with attendees, agenda checklist, decisions block, action items table with owners + dates, and a "next meeting" footer. Use when the brief mentions "meeting notes", "minutes", "1:1 notes", "all-hands recap", or "äžčŪŪįšŠčĶ". | Stars: 108k | Updated | Claude CodeCodex | Verified | Install |