The Ruby on Rails 8 version was released with super cool features and improvements. In this guide, we'll cover the most important tasks you need to accomplish to upgrade your Ruby on Rails 7 application smoothly.
Usually, Rails stays close to the latest Ruby version. Rails 8.0 requires Ruby 3.2.0 or newer.
The following list can help you to finish your Rails update with minimal throwbacks.
- Write tests and make sure they pass;
- Move to the last patch of your current minor version;
- Fix the tests and deprecated features;
- Move to the latest patch version of the next minor version;
- Now repeat the process until you get the pretended Rails version;
These steps will help you to make the best use of the deprecation warning messages.
The first step is update the Rails version on your Gemfile and run the bundle update rails command:
gem 'rails', '~> 8.0.1'
$ bundle update rails
Make sure the bundle update command was successfully completed. You may need to update other dependencies (e.g., Other gems installed on your project).
Rails provides a built-in mechanism for upgrading configuration files. This ensures your app is aligned with Rails 8 defaults.
bin/rails app:update
This command will update several files and configurations across the project. You should see something like this during the task execution.
$ bin/rails app:update
exist config
conflict config/application.rb
Overwrite /myapp/config/application.rb? (enter "h" for help) [Ynaqdh]
force config/application.rb
create config/initializers/new_framework_defaults_8_0.rb
...
An important attention point is to compare the changes in the configuration files, such as config/application.rb, config/environments/*, and initializers. The update task could overwrite those files and if you have any custom code/configuration on that you'll need to re-add.
Now it's time to check our assets. Depending on how your application was seted you should run updates on the assets dependencies too. Before the Rails 8, we usually use the Sprockets to handle our JS, CSSs and images but now, the default way is a fresh new project called Propshaft.
As an update, we are considering the use of Sprockets for now. Maybe we can have a full Blog about the migration from Sprockets to Propshaft. Let us know if you would like it!
To check if your assets workings well, just run the assets precompile task and verify if the JavaScript, CSS, and images are loaded as expected in the application:
bin/rails assets:precompile
Upgrading to Rails 8 is an opportunity to adopt the latest features and improvements in the framework. By following a methodical approach starting with understanding changes, updating dependencies, and thoroughly testing you can ensure a smooth transition. While the process requires effort, the resulting performance gains and modernised codebase make it a worthwhile investment.
As the world’s largest Ruby on Rails firm, we have super-specialised professionals who can keep your applications always updated. If you want to know more about or receive a free in-depth security assessment and code audit for your Ruby On Rails application, just let us know.
Happy upgrading!
Ps. if you have any questions
Ask here