When upgrading Rails versions -- especially major versions -- you will run into a lot of unique issues, depending on the exact version, and depending on your app.
However, it is still possible to give some generic advice on how you want to tackle the update in principle.
If you are not really confident about upgrading Rails, have a look at Rails LTS Show archive.org snapshot .
Besides the Rails upgrade itself, you might also want to upgrade your other gems and upgrade your Ruby version.
First decide in how many steps you want to run the upgrade. I suggest to:
5.2.8.12
), since the most errors for this rails version have been solved.If your code base is very large you might need to go in smaller increments. The Rails guides suggest to not skip minor versions, but I have not found that to be necessary, and it will cause some duplicated work.
Upgrading gems at the same time might also be contentious, because it introduces additional complexity. On the other hand, it might also solve compatibility issues in those gems. I prefer to simply upgrade all gems together with Rails.
Take note of patches and quirks for your specific version upgrade: Upgrade Rails: Awareness list . You may want to implement them in a later step but it's helpful to know issues beforehand.
Upgrade Rails and gems
gem 'rails', '= 5.2.1'
).
Gemfile
snippet from the Rails LTS docs.bundle update
Gemfile.lock
.bundle update [gem names]
) the necessary gems first or find a compatible gem version(s) setup by adding constraints to your Gemfile
.Clean out your tmp
folder
Update your Rails config
rails app:update
. This will try to write all configuration like it would for a new Rails app, and show you the diff to your current code.Check the official Rails upgrade guide
Get rails console
running
Get rails console
running with eager loading
config.eager_load = true
in development.rb
.Get rails server
running
rails server
can render a page.Fix tests
Upgrade to new framework defaults Show archive.org snapshot
config/initializers/new_framework_defaults_x_x.rb
one by oneapplication.rb
file with and add a comment for the reasonconfig/initializers/new_framework_defaults_x_x.rb
and change the config.load_defaults
to the new Rails version.Fix deprecation warnings.
If you have added many constraints in your Gemfile
to find compatible versions, remove or relax those constraints to enable future upgrades.
bundle install
so your Gemfile.lock
updates as well.Keep one commit for every successful rails version update step.
Take care of patches that should be applied: Upgrade Rails: Awareness list