Rails Upgrade Notes

Version by version guide, courtesy of FastRuby.io.


Good advice from Arkency:

Go for tactical DDD patterns for your core domain. Modularize your code, extract Bounded Contexts. Use Rails where they shine: ApplicationController, ActiveRecord used for writes and reads without the callback hell and STI. We’ve shown you the alternative approach many times: commands, service objects, process managers, etc. Believe us, your next upgrade will be just a matter of Rails version bump in your Gemfile.

Via Rubocop

It should be possible to leverage Rubocop to migrate a bunch of mechanical/api changes. For example, upgrading Rails 4 -> 5 on a recent project, this would be a trivial change to automate a rewrite:

1
2
-  before_filter :ensure_policy_access
+  before_action :ensure_policy_access

Especially on larger teams with existing work going along parallel to upgrade work, it’s very worthwhile to write some rewrite cops to both ease merging new features into an upgrade branch, and to act as a reminder/safety net after the upgrade hits master to guide other developers.

In fact, the rubocop-rails gem may actually cover

See this article for a starter example, and this article that stands up an example workflow with what I think are some cops already in core Rubocop.

Via Synvert

Synvert is a generic code-rewriter, which comes with a bunch of Ruby/Rails rules. Also seems reasonably easy to write your own, and has a GUI that will allow you to provide before/after examples and will generate the appropriate code for you.