Rails Upgrade
Rails Upgrade
io
Chapters
Chapter 1: Getting Started 1
Chapter 2: Deprecation Warnings 2
Chapter 3: From Rails 2.3 to 3.0 3
Chapter 4: From Rails 3.0 to 3.1 4
Chapter 5: From Rails 3.1 to 3.2 5
Chapter 6: From Rails 3.2 to 4.0 6
Chapter 7: From Rails 4.0 to 4.1 7
Chapter 8: From Rails 4.1 to 4.2 8
Chapter 9: From Rails 4.2 to 5.0 9
Chapter 10: From Rails 5.0 to 5.1 10
Chapter 11: From Rails 5.1 to 5.2 11
Chapter 12: From Rails 5.2 to 6.0 12
Chapter 13: From Rails 6.0 to 6.1 13
Chapter 14: Next Steps 14
Chapter 15: Need Help? 15
4th Edition
Chapter 1: Getting Started FastRuby.io
Caveats
Not all applications are good candidates for a Rails
upgrade project. We strongly advise against upgrading
big applications which are running in production with
minimal test coverage.
4th Edition
Chapter 1: Getting Started FastRuby.io
The Guide
The advice in this guide comes from working on many
upgrade projects and what we have learned in the
process. We recommend that you follow these
instructions as much as possible to ship a smooth
upgrade.
Patch Versions
4th Edition
Chapter 1: Getting Started FastRuby.io
The first step is to make sure that you are running the
application with the latest patch version. That way,
you make sure that the latest security patches have
been installed. On top of that, with more recent
versions, you will get a series of deprecation warnings
that will be useful in finding out what needs to be
done.
Dependencies
Have you ever gone down the rabbit hole? In order to
upgrade Rails, you need to upgrade dependency A (which
is not compatible with Rails 5.0 because dependency B
which is a dependency of A is not compatible with that
version of ActiveRecord)
Before you start going down the rabbit hole, make sure
to check your Gemfile.lock for incompatibilities. For
that, you can this website: https://railsbump.org/
4th Edition
Chapter 1: Getting Started FastRuby.io
4th Edition
Chapter 1: Getting Started FastRuby.io
if next?
gem 'rails', '~> 6.0.0'
else
gem 'rails', '~> 5.2.3'
end
4th Edition
Chapter 1: Getting Started FastRuby.io
if next?
gem "dep", "~> 1.2.3"
else
gem "dep", "~> 0.9"
end
version branch with all the dual boot code and open a PR
that will target master. The idea is that from now on,
every PR that you create and can't be merged to master
4th Edition
Chapter 1: Getting Started FastRuby.io
At this point, if you run the test suite using the new
version of Rails, it's highly likely that a bunch of
tests will fail. It's time to address them and open a
pull request for each one or for each root cause,
depending of the complexity of the changes.
4th Edition
Chapter 1: Getting Started FastRuby.io
Deployments
Once you have submitted and deployed all the backwards
compatible changes you could think of and gotten rid of
all deprecation warnings, it is time to deploy.
4th Edition
Chapter 1: Getting Started FastRuby.io
4th Edition
Chapter 1: Getting Started FastRuby.io
Chapter 3: Deprecation
Warnings
Deprecation warnings are a common thing in our
industry. They are warnings that notify us that a
specific feature (e.g. a method) will be removed soon
(usually in the next minor or major version) and should
be replaced with something else. Features are
deprecated rather than immediately removed, in order to
provide backward compatibility (a solution that works
in both the current and the future version), and to
give programmers time to implement the code in a way
that follows the new standard.
If you have good test coverage, you can run the whole
test suite and look at the logs that were generated. If
you are using a CI service (like CircleCI or Travis CI)
you can easily see the logs once the build finishes
running. Otherwise, if you run the tests locally, you
can look at the output in the console or in the
log/test.log file.
4th Edition
Chapter 1: Getting Started FastRuby.io
# config/environments/production.rb
config.active_support.deprecation = :notify
# config/initializers/deprecation_warnings.rb
ActiveSupport::Notifications
.subscribe('deprecation.rails') do |name, start, finish, id, payload|
# Example if you use Honeybadger:
Honeybadger.notify(
error_class: "deprecation_warning",
error_message: payload[:message],
backtrace: payload[:callstack]
)
end
4th Edition
Chapter 1: Getting Started FastRuby.io
4th Edition
Chapter 1: Getting Started FastRuby.io
After that, you can create a new pull request and move
on to the next deprecation warning on your backlog.
Best Practices
In order to not accumulate deprecation warnings in your
application, it is a good practice to treat them as
errors. You can easily configure that in your
config/environments/test.rb and config/environments/development.rb
files:
config.active_support.deprecation = :raise
Avoiding Regressions
Rubocop
4th Edition
Chapter 1: Getting Started FastRuby.io
# config/environments/test.rb
ActiveSupport::Deprecation.disallowed_behavior = [:raise]
ActiveSupport::Deprecation.disallowed_warnings = [
"uniq",
:uniq,
/(uniq)!?/,
]
4th Edition
Chapter 1: Getting Started FastRuby.io
1. Considerations
2. Ruby version
3. Tools
4. XSS protection
5. Config files
6. Gems
7. Deprecations
Active Record
Action Mailer
Metal
Railties
8. Next steps
1. Considerations
Before beginning with the upgrade process, we recommend
that each version of your Rails app has the latest
patch version before moving to the next major/minor
version. For example, in order to follow this article,
your Rails version should be at 2.3.18 before updating
to Rails 3.0.20.
2. Ruby version
4th Edition
Chapter 1: Getting Started FastRuby.io
3. Tools
There is an official plugin that helps the upgrade
process. You just need to install the script by doing
script/plugin install git://github.com/rails/rails_upgrade.git and
then run rake rails:upgrade:check to see most of the files
you need to upgrade in your application. It also
provides some other generators to upgrade specific
areas in your app like routes or gems.
4. XSS protection
In this version, Rails automatically adds XSS
protection in order to escape any content, so you will
probably need to update your templates according to
this. Luckily there is an official plugin for this. We
recommend you take a look at it.
5. Config files
Rails 3 introduces the concept of an Application
object. An application object holds all the specific
4th Edition
Chapter 1: Getting Started FastRuby.io
6. Gems
Bundler is the default way to manage Gem dependencies
in Rails 3 applications. You will need to add a Gemfile
in the root of your app, define all your gems there,
and then get rid of the config.gem statements.
4th Edition
Chapter 1: Getting Started FastRuby.io
# Before:
config.gem 'aws-sdk', :version => '1.0.0' # (config/environment.rb)
# Now:
(Gemfile)
group :development do
gem 'pry', '~> 0.6.0'
end
7. Deprecations
There are a bunch of deprecations that happen during
this version:
Active Record
The method to define a named scope is now called
scope instead of named_scope .
4th Edition
Chapter 1: Getting Started FastRuby.io
# Before:
named_scope :active, :conditions => ["active = ?", true]
# Now:
scope :active, where("active = ?", true)
# Before:
validates_presence_of :email
# Now:
validates :email, presence: true
ActiveRecord::Base.colorize_logging and
config.active_record.colorize_logging are deprecated in
favor of Rails::LogSubscriber.colorize_logging or
config.colorize_logging .
Action Mailer
:charset , :content_type , :mime_version ,
:implicit_parts_order are all deprecated in favor of
ActionMailer.default :key => value style declarations.
Mailer dynamic create_method_name and deliver_method_name
4th Edition
Chapter 1: Getting Started FastRuby.io
# Before:
message = UserMailer.create_welcome_email(user)
UserMailer.deliver(message)
or
UserMailer.deliver_welcome_email(user)
# Now:
UserMailer.welcome_email(user).deliver
# Before:
def welcome_email(user)
...
body {:user => user, :url => "https://fastruby.io"}
end
# Now:
def welcome_email(user)
...
@user = user
@url = "https://fastruby.io"
end
4th Edition
Chapter 1: Getting Started FastRuby.io
Metal
Since Rails 3 is closer to Rack, the Metal abstraction
is no longer needed.
Railties
Railties deprecates the following constants during this
version:
4th Edition
Chapter 1: Getting Started FastRuby.io
# Before:
vendor/plugins/ombulabs_patches/tasks/s3_backup.rake
# Now:
lib/tasks/ombulabs_patches/s3_backup.rake
8. Next steps
At this point your application should be properly
running in Rails 3.0. In the next chapter we will talk
about the migration from Rails 3.0 to Rails 3.1.
4th Edition
Chapter 1: Getting Started FastRuby.io
1. Considerations
2. Ruby version
3. Tools
4. Config files
5. jQuery
6. Asset Pipeline
7. Next steps
1. Considerations
Before beginning with the upgrade process, we recommend
that each version of your Rails app has the latest
patch version before moving to the next major/minor
version. For example, in order to follow this article,
your Rails version should be at 3.0.20 before updating
to Rails 3.1.12
2. Ruby version
Rails 3.1 requires Ruby 1.8.7 or higher, but no more
than 1.9.3. If you want to use Ruby 1.9.x, we recommend
you skip directly to 1.9.3. Also Ruby 1.9.1 is not
4th Edition
Chapter 1: Getting Started FastRuby.io
3. Tools
Rails 3.1 comes with a generator that helps the upgrade
process. You just need to run rake rails:update to see a
guide that details how to upgrade your application.
4. Config files
You should remove any references to
ActionView::Base.debug_rjs in your project.
# (config/environments/development.rb)
config.action_view.debug_rjs = true
4th Edition
Chapter 1: Getting Started FastRuby.io
# Enable parameter wrapping for JSON. You can disable this by setting :f
ActiveSupport.on_load(:action_controller) do
wrap_parameters :format => [:json]
end
5. jQuery
jQuery is the default JavaScript library that comes
with Rails 3.1.
gem 'jquery-rails'
4th Edition
Chapter 1: Getting Started FastRuby.io
6. Asset Pipeline
The Rails Asset Pipeline is an optional feature in
Rails 3.1, but we recommend including it to take
advantage of its capabilities. In order to include it,
you should apply the following changes:
group :assets do
gem 'sass-rails', "~> 3.1.5"
gem 'coffee-rails', "~> 3.1.1"
gem 'uglifier', ">= 1.0.3"
end
config.assets.enabled = true
config.assets.version = '1.0'
# Defaults to '/assets'
config.assets.prefix = '/asset-files'
4th Edition
Chapter 1: Getting Started FastRuby.io
# Defaults to Rails.root.join("public/assets")
# config.assets.manifest = YOUR_PATH
# Configure static asset server for tests with Cache-Control for perform
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
7. Next steps
After you get your application properly running in
Rails 3.1, you will probably want to keep working on
this Rails upgrade journey.
4th Edition
Chapter 1: Getting Started FastRuby.io
1. Considerations
2. Ruby version
3. Tools
4. Config files
5. Gemfile
6. Deprecations
7. Next steps
1. Considerations
Before beginning with the upgrade process, we recommend
that each version of your Rails app has the latest
patch version before moving to the next major/minor
version. For example, in order to follow this article,
your Rails version should be at 3.1.12 before updating
to Rails 3.2.22
2. Ruby version
Depending on which patch version of Rails 3.2 you are
using, the Ruby versions that you can use will change.
Since we recommend that you always use the latest patch
4th Edition
Chapter 1: Getting Started FastRuby.io
3. Tools
Rails 3.2 comes with a generator that helps you to
update the configuration files. The rake rails:update
4. Config files
There are a few settings that you need to add to your
environment filters.
Add to config/environments/development.rb
4th Edition
Chapter 1: Getting Started FastRuby.io
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
Add to config/environments/test.rb
5. Gemfile
You should update a couple of gems inside your assets
group:
group :assets do
gem 'sass-rails', '~> 3.2.6'
gem 'coffee-rails', '~> 3.2.2'
gem 'uglifier', '>= 1.0.3'
end
6. Deprecations
Rails 3.2 deprecates vendor/plugins , and it's the last
Rails version that supports it. If your plan is to
migrate to Rails 4 in the future, you can start
replacing any plugins by extracting them to gems and
4th Edition
Chapter 1: Getting Started FastRuby.io
7. Next steps
After you get your application properly running in
Rails 3.2, you will probably want to keep working on
this Rails upgrade journey.
4th Edition
Chapter 1: Getting Started FastRuby.io
1. Ruby version
2. Gems
3. Config files (config/)
4. Application code
i. Models (app/models/)
ii. Controllers (app/controllers/)
5. Tests
6. Miscellaneous
7. Upgrading gems
8. Next steps
1. Ruby version
Rails 3.2.x is the last version to support Ruby 1.8.7.
If you're using Ruby 1.8.7, you'll need to upgrade to
Ruby 1.9.3 or newer. The Ruby upgrade is not covered in
this guide, but check out this guide for more details
on that.
2. Gems
4th Edition
Chapter 1: Getting Started FastRuby.io
3. Config files
Rails includes the rails:update task. You can use this
task as a guideline as explained thoroughly in this
post. It will help you get rid of unnecessary code or
monkey patches in your config files and initializers,
especially if your Rails 3 app was running on Rails 2.
4th Edition
Chapter 1: Getting Started FastRuby.io
4. Application code
a. Models
All dynamic finder methods except for .find_by_... are
deprecated:
# before:
Authentication.find_all_by_provider_and_uid(provider, uid)
# after:
Authentication.where(provider: provider, uid: uid)
4th Edition
Chapter 1: Getting Started FastRuby.io
# before:
default_scope where(deleted_at: nil)
# after:
default_scope { where(deleted_at: nil) }
# before:
has_many :posts, order: 'position'
# after:
has_many :posts, -> { order('position') }
4th Edition
Chapter 1: Getting Started FastRuby.io
b. Controllers
ActionController Sweeper was extracted into the
rails-observers gem, you can regain usage by adding
the gem to your Gemfile:
caches_page :public
4th Edition
Chapter 1: Getting Started FastRuby.io
or:
5. Tests
From Ruby 1.9.x onwards, you have to include the test-
6. Miscellaneous
Routes now require you to specify the request
method, so you no longer can rely on the catch-all
default.
# change:
match '/home' => 'home#index'
# to:
match '/home' => 'home#index', via: :get
# or:
get '/home' => 'home#index'
4th Edition
Chapter 1: Getting Started FastRuby.io
7. Upgrading gems
If you're using any non-standard gems, you're probably
going to enjoy this section.
4th Edition
Chapter 1: Getting Started FastRuby.io
4th Edition
Chapter 1: Getting Started FastRuby.io
8. Next steps
After you get your application properly running in
Rails 4.0, you will probably want to keep working on
this Rails upgrade journey. In the next chapter we will
talk about the migration from Rails 4.0 to Rails 4.1.
4th Edition
Chapter 1: Getting Started FastRuby.io
1. Ruby version
2. Gems
3. Config files (config/)
4. Application code
i. Callbacks
ii. ActiveRecord
5. Tests
6. Miscellaneous
7. Next steps
1. Ruby version
Rails 4.1 requires Ruby 1.9.3 or later. Ruby 1.8.7
support was dropped in Rails 4.0, so you should already
be running 1.9.3 or later. For Rails 4.1, Ruby 2.0 (or
newer) is preferred according to the official upgrade
guide.
2. Gems
4th Edition
Chapter 1: Getting Started FastRuby.io
3. Config files
Rails includes the rails:update task. You can use this
task as a guideline as explained thoroughly in this
post.
4. Application code
a. Callbacks
Return from callbacks is no longer allowed:
Before:
After:
before_save { false }
See: https://github.com/rails/rails/pull/13271
4th Edition
Chapter 1: Getting Started FastRuby.io
b. ActiveRecord
Removal of deprecated finders:
activerecord-deprecated_finders
(https://github.com/rails/activerecord-
deprecated_finders) was removed as a dependency from
Rails 4.1. You will need to migrate away from dynamic
finders.
Before:
User.find_all_by_email(email)
After:
User.where(email: email)
Before:
User.find_last_by_email(email)
After:
User.where(email: email).last
Also:
4th Edition
Chapter 1: Getting Started FastRuby.io
gem 'activerecord-deprecated_finders'
# ...
end
> User.inactive
SELECT "users".* FROM "users" WHERE "users"."active" = 'false'
> User.all
SELECT "users".* FROM "users" WHERE "users"."active" = 'true'
> User.inactive
SELECT "users".* FROM "users" WHERE "users"."active" = 'true'
AND "users"."active" = 'false'
method (source).
4th Edition
Chapter 1: Getting Started FastRuby.io
Before:
After:
Post.includes(:comments).where("comments.title = 'foo'")
Post.joins(:comments).where("comments.title = 'foo'")
4th Edition
Chapter 1: Getting Started FastRuby.io
Post.eager_load(:comments).where("comments.title = 'foo'")
Or:
Post.includes(:comments).where("comments.title = 'foo'").references(:com
5. Tests
CSRF protection now covers GET requests with JS
responses:
instead of get :
Before:
4th Edition
Chapter 1: Getting Started FastRuby.io
After:
See: https://github.com/rails/rails/pull/13345
6. Miscellaneous
Flash message keys are strings now:
Before:
flash.to_hash.except(:notify)
After:
flash.to_hash.except("notify")
7. Next steps
If you successfully followed all of these steps, you
should now be running Rails 4.1! In the next chapter we
will talk about the migration from Rails 4.1 to Rails
4.2.
4th Edition
Chapter 1: Getting Started FastRuby.io
1. Ruby version
2. Gems
3. Config files (config/)
4. Application code
i. ActiveRecord
ii. ActionMailer
5. Miscellaneous
6. Next steps
1. Ruby version
Rails 4.2 requires Ruby 1.9.3 or later, and Ruby 2.0
(or newer) is preferred according to the official
upgrade guide.
2. Gems
If you're using RSpec 2, you'll need to migrate to
RSpec 3, since RSpec 2 doesn't officially support Rails
4.2. To make this process easier, you can update to
RSpec 2.99, which will print a bunch of deprecation
4th Edition
Chapter 1: Getting Started FastRuby.io
3. Config files
Rails includes the rails:update task. You can use this
task as a guideline as explained thoroughly in this
post.
4th Edition
Chapter 1: Getting Started FastRuby.io
4. Application code
a. ActiveRecord
ActiveRecord <= 4.2 suppresses exceptions raised in the
after_commit and after_rollback callbacks by default. They
are rescued and printed on the log, and they don't
propagate. You can opt in to raising these exceptions
now by adding the following configuration:
config.active_record.raise_in_transactional_callbacks = true
See: https://github.com/rails/rails/pull/16537
4th Edition
Chapter 1: Getting Started FastRuby.io
Before:
Comment.find(comment)
After:
Comment.find(comment.id)
b. ActionMailer
deliver and deliver! are deprecated, in favor of
deliver_now and deliver_now! .
Before:
NotificationMailer.daily_summary(user).deliver
After:
NotificationMailer.daily_summary(user).deliver_now
5. Miscellaneous
respond_with and the class-level respond_to were removed
from Rails 4.2 and moved to the responders gem.
4th Edition
Chapter 1: Getting Started FastRuby.io
to your Gemfile .
gem 'rails-deprecated_sanitizer'
6. Next steps
If you successfully followed all of these steps, you
should now be running Rails 4.2! In the next chapter we
will take you from Rails 4.2 to 5.0.
4th Edition
Chapter 1: Getting Started FastRuby.io
1. Ruby version
2. Gems
3. Config files (config/)
4. Application code
i. ActiveRecord
ii. Controllers
5. Testing
6. Next steps
1. Ruby version
Rails 5.0 requires Ruby 2.2.2 or later.
gem 'test-unit'
4th Edition
Chapter 1: Getting Started FastRuby.io
2. Gems
It's recommended that you check your Gemfile against
RailsBump to ensure all your gems are compatible with
Rails 5. As of the release of this blog post, there are
only a few gems which don't support Rails 5 yet. This
is more of a problem when you're upgrading early on.
3. Config files
Rails includes the rails app:update task. You can use this
task as a guideline as explained thoroughly in this
post.
4. Application code
a. ActiveRecord
ActiveRecord models will now inherit from
ApplicationRecord by default instead of
ActiveRecord::Base. You should create an
application_record.rb file under app/models </span>with:
4th Edition
Chapter 1: Getting Started FastRuby.io
b. Controllers
If you're not already using strong parameters, and
still rely on protected_attributes , you should migrate
your application to strong parameters before attempting
to upgrade to Rails 5.0. protected_attributes is no longer
supported on Rails 5.0.
4th Edition
Chapter 1: Getting Started FastRuby.io
5. Testing
One of the most common methods in controller tests,
assigns , has been extracted from Rails and moved to the
rails-controller-testing gem. If you wish to continue using
it (and assert_template ), you'll need to add it to your
Gemfile :
gem 'rails-controller-testing'
6. Next steps
If you successfully followed all of these steps, you
should now be running Rails 5.0! In the next chapter we
will discuss API changes in the Rails 5.2 release.
4th Edition
Chapter 1: Getting Started FastRuby.io
4th Edition
Chapter 1: Getting Started FastRuby.io
1. Ruby version
2. Gems
3. Config files
4. Application code
i. ActiveRecord
ii. Controllers
5. Testing
6. Next steps
1. Ruby version
Like Rails 5.0, Rails 5.1 requires Ruby 2.2.2 or later.
2. Gems
Make sure the gems you use are compatible with Rails
5.1, you can check this using RailsBump. If a gem is
missing on RailsBump, you'll need to manually check
the Github page for the project to find out its
status. In case you own the gem, you'll need to make
sure it supports Rails 5.1 and if it doesn't, update
it.
4th Edition
Chapter 1: Getting Started FastRuby.io
3. Config files
Rails includes the rails app:update task. You can use
this task as a guideline as explained thoroughly in
this post.
Before:
config.serve_static_files = false
config.static_cache_control = "public, max-age=3600"
After:
config.public_file_server.enabled = false
config.public_file_server.headers = "public, max-age=3600"
4. Application code
4.1. ActiveRecord
The raise_in_transactional_callbacks option is now
removed. It was already deprecated and covered in a
previous upgrade.
4th Edition
Chapter 1: Getting Started FastRuby.io
4.2. Controllers
Before Rails 5.1, conditions in filters could be
invoked using strings. They now have to be symbols:
Before
After:
Before:
skip_before_filter :authenticate_user!
before_filter :authenticate_user!
after_filter :do_something
After:
4th Edition
Chapter 1: Getting Started FastRuby.io
skip_before_action :authenticate_user!
before_action :authenticate_user!
after_action :do_something
5. Testing
Parameters in controller tests now need a params
key:
Before:
After:
6. Next steps
If you successfully followed all of these steps, you
should now be running Rails 5.1! In the next chapter we
will show you how to upgrade from Rails 5.1 to Rails
5.2.
4th Edition
Chapter 1: Getting Started FastRuby.io
1. Ruby version
2. Gems
3. Config files
4. Application code
i. Active Storage
ii. Credentials
iii. ActiveRecord::Dirty
5. Next steps
1. Ruby version
Like Rails 5.0 and 5.1, Rails 5.2 requires at least
Ruby 2.2.2.
2. Gems
At the time of writing, the Rails 5.2 release is
relatively recent, which means that some gems may still
not be fully compatible, or contain deprecation
warnings if you're not using their latest version.
RailsBump can help you check if the gem is compatible
4th Edition
Chapter 1: Getting Started FastRuby.io
3. Config files
Rails includes the rails app:update task. You can use
this task as a guideline as explained thoroughly in
this post.
4. Application code
There were not too many deprecations between 5.1 and
5.2 compared to past releases (see the full changelog
here).
4th Edition
Chapter 1: Getting Started FastRuby.io
a. Active Storage
Active Storage is a replacement for Paperclip and other
gems, like Shrine. Paperclip in particular has been
deprecated. If you're using Paperclip, the maintainers
wrote an in-depth migration guide which you can follow
here.
b. Credentials
Another major feature is the introduction of
Credentials. It will eventually replace the current
config/secrets.yml . Since there are also encrypted secrets
( config/secrets.yml.enc ), its intention is to clear up the
confusion.
4th Edition
Chapter 1: Getting Started FastRuby.io
Previous behavior
Notice the deprecation warnings we get when calling
email_changed? , changed? , changes and previous_changes in
Rails 5.1 from within an after_save callback:
4th Edition
Chapter 1: Getting Started FastRuby.io
4th Edition
Chapter 1: Getting Started FastRuby.io
New behavior
A developer's intentions will become more clear with
the behavior changes introduced in Rails 5.2:
4th Edition
Chapter 1: Getting Started FastRuby.io
4th Edition
Chapter 1: Getting Started FastRuby.io
Must do:
After modifying an object and after saving to the
database, or within after_save :
4th Edition
Chapter 1: Getting Started FastRuby.io
5. Next steps
If you successfully followed all of these steps, you
should now be running Rails 5.2! In the next chapter we
will take you from Rails 5.2 to Rails 6.0.
4th Edition
Chapter 1: Getting Started FastRuby.io
1. Considerations
2. Ruby version
3. Gems
4. Config files
5. Removals
Railties
Action Pack
Action View
Active Record
6. Webpacker
7. Credentials
8. Next steps
1. Considerations
Before beginning with the upgrade process, we recommend
that each version of your Rails app has the latest
patch version before moving to the next major/minor
version. For example, in order to follow this article,
your Rails version should be at 5.2.3 before upgrading
to Rails 6.0.x
2. Ruby version
4th Edition
Chapter 1: Getting Started FastRuby.io
3. Gems
Make sure you check the Github page of the gems you use
for the project to find out its compatibility with
Rails 6.0. In case you own the gem, you'll need to make
sure it supports Rails 6.0 and if it doesn't, update
it.
4. Config files
Rails includes the rails app:update task. You can use
this task as a guideline as explained thoroughly in
this post.
5. Removals
Railties
4th Edition
Chapter 1: Getting Started FastRuby.io
Action Pack
Action View
Active Record
Remove deprecated
ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_t
ype? .
4th Edition
Chapter 1: Getting Started FastRuby.io
6. Webpacker
Webpacker is now the default JavaScript compiler for
Rails 6. You can still manage your JavaScript using the
Asset Pipeline but it might be a good idea to start
migrating to Webpack.
7. Credentials
Rails 6 adds support for multi environment credentials.
That means that now you can run rails credentials:edit --
4th Edition
Chapter 1: Getting Started FastRuby.io
8. Next steps
If you successfully followed all of these steps, you
should now be running Rails 6.0! In the next chapter we
will take you from Rails 6.0 to Rails 6.1.
4th Edition
Chapter 1: Getting Started FastRuby.io
1. Preparations
2. Ruby version
3. Gems
4. Config files
5. Rails Guides
6. Removals
Railties
Action Pack
Action View
Action Mailer
Active Record
Active Storage
Active Support
7. Next steps
1. Preparations
Before beginning with the upgrade process, we have some
recommended preparations:
4th Edition
Chapter 1: Getting Started FastRuby.io
2. Ruby version
Rails 6.1 requires Ruby 2.5 or later. Check out this
table to see all the required Ruby versions across all
Rails versions.
3. Gems
Make sure you check the GitHub page of the gems you use
for the project to find out its compatibility with
Rails 6.1. In case you are the maintainer of the gem,
you'll need to make sure it supports Rails 6.1 and if
it doesn't, update it. A great site to checkout
compatibility is RailsBump.
4. Config files
Rails includes the rails app:update task. You can use
this task as a guideline as explained thoroughly in
this post.
4th Edition
Chapter 1: Getting Started FastRuby.io
5. Rails Guides
It is important to check through the official Rails
Guides and follow any of the steps necessary for your
application.
6. Removals
If you have ignored deprecation warnings on past
version jumps, and haven’t been staying up to date with
them you may find that you have issues with broken
tests or broken parts of the application. If you have
trouble figuring out why something is broken it may be
because a deprecation is removed, so you can check
through this list to see if this may be the case.
Railties
dbconsole command.
4th Edition
Chapter 1: Getting Started FastRuby.io
Action Pack
Action View
4th Edition
Chapter 1: Getting Started FastRuby.io
Remove deprecated
ActionView::Template.finalize_compiled_template_methods and
config.action_view.finalize_compiled_template_methods .
Action Mailer
4th Edition
Chapter 1: Getting Started FastRuby.io
Active Record
Remove deprecated
ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_multi_ins
ert? .
Remove deprecated
ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_foreign_k
eys_in_create? .
Remove deprecated
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#supports_ranges?
.
Remove deprecated
config.active_record.sqlite3.represent_boolean_as_integer .
Active Storage
4th Edition
Chapter 1: Getting Started FastRuby.io
operations to ActiveStorage::Transformers::ImageProcessing .
Remove deprecated
ActiveStorage::Transformers::MiniMagickTransformer .
Remove deprecated config.active_storage.queue .
Remove deprecated ActiveStorage::Downloading .
Active Support
config.i18n.fallbacks is empty.
Remove deprecated
ActiveSupport::LoggerThreadSafeLevel#after_initialize .
4th Edition
Chapter 1: Getting Started FastRuby.io
and ActiveSupport::Multibyte::Chars#normalize .
Remove
deprecated ActiveSupport::Multibyte::Unicode.pack_graphemes ,
ActiveSupport::Multibyte::Unicode.unpack_graphemes ,
ActiveSupport::Multibyte::Unicode.normalize ,
ActiveSupport::Multibyte::Unicode.downcase ,
ActiveSupport::Multibyte::Unicode.upcase and
ActiveSupport::Multibyte::Unicode.swapcase .
Remove
deprecated ActiveSupport::Notifications::Instrumenter#end= .
7. Next steps
If you successfully followed all of these steps, you
should now be running Rails 6.1!
4th Edition
Chapter 1: Getting Started FastRuby.io
Circle CI
You can add a second job to use the Gemfile.next file:
4th Edition
Chapter 1: Getting Started FastRuby.io
jobs:
"build-rails-5-2":
docker:
# this is your original config ...
- image: circleci/ruby:2.6.0-node-browsers
environment:
- PGHOST=localhost
- PGUSER=ubuntu
- RAILS_ENV=test
- RACK_ENV=test
- COVERAGE=true
- DATABASE_URL=postgres://ubuntu@localhost:5432/piedpiper_test
# ...
"build-rails-6-0":
docker:
# this is the next rails config ...
- image: circleci/ruby:2.6.0-node-browsers
environment:
- PGHOST=localhost
- PGUSER=ubuntu
- RAILS_ENV=test
- RACK_ENV=test
- COVERAGE=true
- DATABASE_URL=postgres://ubuntu@localhost:5432/piedpiper_test
- BUNDLE_GEMFILE=Gemfile.next
# ...
workflows:
version: 2
build:
jobs:
- "build-rails-5-2"
- "build-rails-6-0"
Travis CI
4th Edition
Chapter 1: Getting Started FastRuby.io
sudo: false
language: ruby
cache:
bundler: true
directories:
- travis_phantomjs
rvm:
- 2.2.6
gemfile:
- Gemfile
- Gemfile.next
services:
- memcached
- postgresql
addons:
postgresql: "9.4"
before_install:
- gem install bundler -v 1.16.2
before_script:
- bundle install
- psql -c 'create database epets_test;' -U postgres
- RAILS_ENV=test bundle exec rake db:structure:load
script: RAILS_ENV=test bundle exec rake
section.
4th Edition
Chapter 1: Getting Started FastRuby.io
These tips will help you next time you need to upgrade
the minor/major version of Rails!
4th Edition
Chapter 1: Getting Started FastRuby.io
4th Edition