Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

thomasvanholder
thomasvanholder

Posted on • Edited on

     

How to upgrade Rails 6.1 to Rails 7

  1. Update rails in gemfile
  2. Upgrade rails packages
  3. Add sprockets to gemfile
  4. Run update rails task
  5. Verify framework defaults
  6. Verify depreciated methods

How to upgrade an exising application to Rails 7. Note that Rails 7 requires Ruby 2.7.0 or newer.


1. Update rails in gemfile

# oldgem"rails","~> 6.1.4"# newgem"rails","~> 7.0.0"
Enter fullscreen modeExit fullscreen mode

In the terminal run:

bundle update
Enter fullscreen modeExit fullscreen mode

2. Upgrade rails packages

In thepackage.json file, find all @rails packages and upgrade then one by one. For example:

yarn upgrade @rails/actioncable--latestyarn upgrade @rails/activestorage--latestyarn upgrade @rails/request.js--latest
Enter fullscreen modeExit fullscreen mode

3. Add sprockets to gemfile

When you are using the asset pipeline, assets related errors can pop up when running a rails command.
Example:

# - Don't know how to build task 'assets:precompile'# - 'method_missing': undefined method `assets'
Enter fullscreen modeExit fullscreen mode

Add sprockets to the gem file as it's now anoptional depedency.

gem"sprockets-rails"
Enter fullscreen modeExit fullscreen mode
bundleinstall
Enter fullscreen modeExit fullscreen mode

4. Run update rails task

bin/rails app:update
Enter fullscreen modeExit fullscreen mode

This will prompt you file by file to integrate the new rails 7 defaults.

Example:
Overwrite .../config/boot.rb? (enter "h" for help) [Ynaqdhm]
Note: pressh to see the menu options.

Go through every file to inspect the difference between the default set-up of rails 7 and your current configuration.

You can open the files in your editor to compare when selecting merge (m). If you run into the following error:
Please specify merge tool to 'THOR_MERGE' env
Run the app:update command again with your editor specified.

For example (vs code)

THOR_MERGE=code bin/rails app:update
Enter fullscreen modeExit fullscreen mode

After completing the set-up runrails db:migrate to migrate the newly added active storage migration file.

❗️ If you have set-up other environments, non-default enviroments, likestaging.rb make sure to update that file too.


5. Verify framework defaults

After completing thebin/rails app:update from the step 4, Rails creates anew_framework_defaults_7.0.rb file inconfig/initializers. This file helps you to make a big upgrade a little easier by flipping on the new default settings one-by-one in multiple deployments.

Theapplication.rb file's settingload_defaults specifies which rails version's default settings to load. This means you can temporarily utilize the default configuration settings from Rails 6.1 while running Rails 7.

# Initialize configuration defaults for originally generated Rails version.config.load_defaults6.1
Enter fullscreen modeExit fullscreen mode

Then, gradually turn on each setting and verify your application is still working as intended. Once you've switched on every setting, you can remove thenew_framework_defaults_7.0.rb and flip theload_defaults version in application.rb to 7.0.

How to turn on Rails 7 framework defaults (part 1)

# Initialize configuration defaults for originally generated Rails version.config.load_defaults7.0
Enter fullscreen modeExit fullscreen mode

6. Verify depreciated methods

Your application might use other depreciated features. Read through theRails 6.1 to Rails 7 section to identify and fix any methods call or settings that are no longer supported.


Top comments(6)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
michellelwt profile image
Michelle Loh
  • Education
    Universiti Sains Malaysia
  • Joined
• Edited on• Edited

Consider thisstackoverflow solution before the 5th step if you have some errors like:

PG::UndefinedTable: ERROR: relation "active_storage_blobs" does not exist
Enter fullscreen modeExit fullscreen mode
CollapseExpand
 
michellelwt profile image
Michelle Loh
  • Education
    Universiti Sains Malaysia
  • Joined

Hey@thomasvanholder , I followed the steps in the post and I noticed that thepackage.json has no changes compared to those newly created rails 7 app, why is it like that? (Beginner learning ruby on rails)

CollapseExpand
 
pavelloz profile image
Paweł Kowalski
Performance, JavaScript, Serverless, and Testing enthusiast.
  • Location
    Earth, Milky Way
  • Work
    Senior Performance Engineer at platformOS
  • Joined

I think upgrading gem is only the beginning (1%?). The fun starts with updating application code.

CollapseExpand
 
thomasvanholder profile image
thomasvanholder
writes code: ruby on rails, stimulus, hotwire and tailwindcss.
  • Joined

Installing the gem is the easy part indeed!

CollapseExpand
 
gisegalaburri profile image
Gisele Galaburri
  • Work
    Software Engineer
  • Joined

I think the 5th step isn't necessary when you upgrade a recently created app.
I mean, you can load_defaults of rails 7.0 without problem

CollapseExpand
 
railsup_sedin profile image
Raisa Kanagaraj
RailsUp is a free, innovative tool that makes Ruby on Rails upgrades seamless and stress-free. It provides a detailed analysis of your app’s gem compatibility, vulnerability, and complexity.

Upgrading from Rails 6.1 to Rails 7 can be challenging, especially when manually checking gem compatibility. To save time and avoid potential issues, tryRailsUp, a free gems compatibility checker tool.

With RailsUp, you can:

  • Upload your Gemfile.lock.
  • Get a detailed report on outdated or incompatible gems.
  • Plan your upgrade with insights into complexity and estimated timelines.

RailsUp simplifies the process of starting your upgrade journey. Give it a try—it’s free!

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

writes code: ruby on rails, stimulus, hotwire and tailwindcss.
  • Joined

More fromthomasvanholder

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp