[Ruby on Rails (RoR)] Upgrade to Ruby 3 and Rails 6.1
Ruby 3 and Rails 6.1
Ruby 3, whose goal is performance, concurrency, and Typing. Especially about performance, Matz stated “Ruby3 will be 3 times faster than Ruby2” a.k.a. Ruby 3x3.
Rails 6.1 has been released and wow does it have a lot of great stuff! It have implemented improvements to multiple databases, adding support for destroying associations in jobs instead of in-memory, turning errors into objects, and so much more.
Ruby 3.0.0 covers those goals by:
Typing (Static Analysis)
Visit Ruby 3.0.0 Released - https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/ to learn more about Ruby 3.
Rails 6.1 have some of the new functionality:
Strict Loading Associations
Destroy Associations Async
Active Storage Improvements
Disallowed Deprecation Support
Performance Improvements and Bug Fixes!
The classic Autoloader is Deprecated
Visit Rails 6.1: Horizontal Sharding, Multi-DB Improvements, Strict Loading, Destroy Associations in Background, Error Objects, and more! | Riding Rails - https://weblog.rubyonrails.org/2020/12/9/Rails-6-1-0-release/ to learn more about Rails 6.1.0.
Prepare test cases and do a regression testing after version upgrade.
Back up code and data, you can roll back to the previous version when the upgrade fails
rvm get head
Install Ruby 3.
rvm install 3.0.0
Edit the file
The upgrade process will be completed after solving some gem version dependency compatibility issues.
Remember to run the regression testing to discover and solve compatibility issues as early as possible.
Docker, Docker Compose, Kubernetes (K8S)
Remember to change ruby version to 3.0.0 if you use Dockerfile.
Removals, Deprecations or Notable changes, etc
Rails 6.1 ActiveRecord deprecates update_attributes and update_attributes! methods
update_attributes! is deprecated and will be removed from Rails 6.1 (please, use update! instead)
As suggested, we need to,
Replace update_attributes with update
Replace update_attributes! with update!
Visit Ruby on Rails 6.1 Release Notes — Ruby on Rails Guides - https://guides.rubyonrails.org/6_1_release_notes.html to leanrn more Removals, Deprecations or Notable changes, etc.
There may have some gems about version dependency compatibility.
Bundler: You must use Bundler 2 or greater with this lockfile
The issue was with gemfile.lock because our local bundle version and project bundle version was not matching!
You must upgrade gem ‘bundler’ to 2.2.8+.
gem update --system
Exception: ArgumentError: wrong number of arguments (given 4, expected 3) on marginalia-1.8.0
You must upgrade gem ‘marginalia’ to 1.10.0+.
RuntimeError: Couldn’t find Active Storage configuration in config/storage.yml
We need to create the file
config/storage.yml manually, if the file does not exist.
(Object doesn’t support #ai)
It may be the XXX_print that cause this problem.
[amazing-print/amazing_print: Pretty print your Ruby objects with style – in full color and with proper indentation - https://github.com/amazing-print/amazing_print]
awesome-print/awesome_print: Pretty print your Ruby objects with style – in full color and with proper indentation - https://github.com/awesome-print/awesome_print
You cant try to disable them by comment the relevant codes.
NoMethodError (undefined method `encode’ for URI:Module)
gem ‘carrierwave-aliyun’ old version use `URI#encode’ which have been removed from Ruby 3.
You must upgrade gem ‘carrierwave-aliyun’ to 1.2.3+.
Merge branch ‘encode_url’ · huacnlee/[email protected] - https://github.com/huacnlee/carrierwave-aliyun/commit/36c03af0762eb30fe4baac690441c30ed8651520
 Ruby 3.0.0 Released - https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/
 Rails 6.1: Horizontal Sharding, Multi-DB Improvements, Strict Loading, Destroy Associations in Background, Error Objects, and more! | Riding Rails - https://weblog.rubyonrails.org/2020/12/9/Rails-6-1-0-release/
 Active Storage Overview — Ruby on Rails Guides - https://edgeguides.rubyonrails.org/active_storage_overview.html
 ruby on rails - Bundler: You must use Bundler 2 or greater with this lockfile - Stack Overflow - https://stackoverflow.com/questions/53231667/bundler-you-must-use-bundler-2-or-greater-with-this-lockfile
 Rails 6.1 ActiveRecord deprecates update_attributes methods - https://rubyinrails.com/2019/04/09/rails-6-1-activerecord-deprecates-update-attributes-methods/
 Ruby on Rails 6.1 Release Notes — Ruby on Rails Guides - https://guides.rubyonrails.org/6_1_release_notes.html