DEV Community

Fernando
Fernando

Posted on • Edited on

How to upgrade a Ruby on Rails app

The idea for this post came because I couldn’t build a rails app on an M1 Mac computer for various reasons. for one, Ruby and Rails versions were old. However, I could run the app in docker so upgrading this app through docker facilitated the ability to do the upgrade. This blog post assumes you already have your application running in Docker and that you are using docker-compose.

Let's upgrade rails

  1. The first step is of course to make sure that the app works in docker. The newer version of Rails come with a docker file that will run your app locally but older versions don’t have this feature.

  2. Get on the docker container by running, docker-compose exec container_name bash
    make sure to capture the rails version you are on.

      rails -v
    
  3. The next step is to head on to https://railsdiff.org/ to see what changes have been made from the rails version you are on to the want you want to move to.

  • The common practice when upgrading rails is to go to the latest version in the current sequence. for example, say you have an app that is running Rails 6.1.4, then you want to update your Rails to the latest version of Rails 6.1.4. in this example, you want to update rails to 6.1.4.7. if we look at railsdiff.org for the differences in these two versions. in our example, there is not much that we need to change. so let's continue updating rails. Image description

4.The next thing to do back in our application is to run bundle update rails from inside the docker container.

  • This will update the needed gems to the compatible versions of our newly updated rails version. You will see something like the below.

Image description

5.Lastly, make sure to run the update task. the update task will walk you through changes in the rails configuration files and ask you to review the differences.

  rails app:update
Enter fullscreen mode Exit fullscreen mode

this will look something like this:
Image description

6.Our final step is to make sure we run our tests.

```
rails test
```
Enter fullscreen mode Exit fullscreen mode

Great! you have updated your Rails application. Continue doing the same steps for the next rails version and use railsdiff.org as a helping tool.

Conclusion

IMPORTANT At this point you should make sure to run your tests to make sure that everything is working as expected. of course, this implies that you have good test coverage for your entire application. if you have integration tests, make sure those also pass and make changes as needed if they dont. As an extra safety measure, I like to click around and submit forms, etc within my application to make sure the behavior is the same as before.

As a final thought, make sure to read the Rails guides for best practices when upgrading a Rails application. you can see that here:
https://guides.rubyonrails.org/upgrading_ruby_on_rails.html

Thank you for reading. feel free to leave your comments below.

Top comments (0)