Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Should We Upgrade to Rails 5?

DZone's Guide to

Should We Upgrade to Rails 5?

The new Ruby on Rails is out, and it you haven't upgraded yet, you should, as persisting with older versions can lead to some not too fun consequences.

· Web Dev Zone ·
Free Resource

Learn how error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.

Ruby on Rails version 5.1.1 is officially out and in use. While the latest release on May 12th was a minor one, version 5.0 brought some major updates to Rails – including new JavaScript abilities with Yarn and webpack, system tests with Capybara, encrypted secrets, and more (click here to read the full Rails 5 release notes).

You may have discussed upgrading your Rails app with your internal team. Using this new version is a no-brainer for a new project, but should your team take the time to upgrade your existing Ruby on Rails app?

Even aside from its new features, v5 brings numerous benefits. In particular, the Rails core team has been paying a lot of attention to performance, efficiency, and memory usage for this new release.

With the newest version of Rails, your team will be better positioned to squeeze more value out of your organization’s server resources.

Still Running on an Older Version of Rails?

If you're still running Rails v3.x, now is definitely the time to start your upgrade journey. Now that v5 is out in the wild, 3.x is no longer receiving further updates.

Let me repeat that. Ruby on Rails 3.x is no longer actively supported; not even for severe security issues.

You don't want to wait until a major security vulnerability is discovered to start the upgrade process to a more recent Rails version. This would leave your business and customers vulnerable for however long it takes your team to execute that upgrade.

If you're on a version of Rails that's older than 4.2.x, bear in mind that moving to v5 will be a multi-stage upgrade. You should only ever upgrade one minor release at a time (e.g., 4.1 to 4.2 to 5.0 instead of 4.1 directly to 5.0). Otherwise, you can't avail yourself of the deprecation warnings and instead will run into hard-to-debug issues because that behavior has been removed entirely.

If you're several versions behind, don't despair and think you're in for months of work! We recently upgraded a medium-sized app from Rails 3.2 to 4.2 (a three-stage upgrade), and while we encountered several thorny issues (mostly due to external gem dependencies), it only took about thirty hours of developer time all told.

While an upgrade seldom goes entirely without hiccups, the Rails team does an excellent job of making the process as developer-friendly as possible. Along with the release of Rails 5, the Rails team had put together a guide for upgrading from v4.2 to v5, detailing the breaking changes and recently deprecated behavior.

For example, if you're running v4.2.x, your app will already be giving you warnings about the deprecated behavior that will be removed in v5.

Quick tip: Developers might want to set ActiveSupport::Deprecation.debug = true in their development and test environments to turn easy-to-miss deprecation warnings into unignorable hard errors that halt the execution.

If you don't get any deprecation warnings from your v4.2 app, you're likely to have a fairly smooth upgrade to v5!

Upgrading and Rails Gems

One of the most common reasons why Rails developers are held back from staying up-to-date is due to gem dependencies.

If your Ruby on Rails application depends on several external Ruby gems, you may not be able to upgrade. In an ideal world, gem maintainers would have been testing their project on the pre-release versions of v5 so that the gem is fully compatible by the time v5.0 is released, but in reality, some gems that are in less active development will take some time (and testing) to release a v5-compatible gem.

If your team has the resources to contribute, most gem maintainers would be happy to take a pull request that brings Rails 5 support. In our open source community, it’s contributions like this that keep Rails ticking along after all these years. You can also try checking the home repositories of some of your gems that don’t yet have Rails 5 support. There may be a branch on their GitHub that includes support but has not been fully tested and merged just yet.

Not sure if your gems are ready for an upgrade? Check your Rails gem files with Ready4Rails which will tell you which gems are ready to update to Rails 4.x or 5.x. This is another great place to contribute your knowledge – a huge number of Rails gems on this site are marked unknown. If you use one and find out if it’s ready to update or not, leave a comment with your experience.

In Conclusion

Generally speaking, unless you have a compelling reason to stay on an older version of Rails, you should upgrade when you have resources available. Keeping fairly up to date allows you to amortize your upgrade costs by dealing with more frequent small upgrades instead of rare colossal upgrades.

Want to do more research on upgrading your Rails app? Here are some helpful resources.

Editors Note: This post was originally published on April 4, 2016. It has been revamped and updated for accuracy and comprehensiveness and to include details about Ruby on Rails version 5.x.

What’s the best way to boost the efficiency of your product team and ship with confidence? Check out this ebook to learn how Sentry's real-time error monitoring helps developers stay in their workflow to fix bugs before the user even knows there’s a problem.

Topics:
web dev ,ruby on rails ,update

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}