Rails 7.2 Adds app:update Task to be a Rails Command.

Rails 7.2, has made many improvements to speed the development process. One major change was the conversion of app:update task to a Rails command. This change aligns the app:update task with other Rails generators.

Why we use app:update ?

After updating the Rails version in Gemfile, We need to update all the configuration files that match with the Rails version,

Previously, updating the configurations files was a time consuming process that required manual changes. Now with the changes in app:update command, the process can be customized with flags according to our workflow.

Before

Previously in Rails, the bin/rails app:update was a Rake task. This implementation had its limitations, especially when adding command-line flags. Arguments had to be parsed by Rake, which supported only Rake-specific flags.

Here’s how we had run the update command:

  $ bin/rails app:update -P | head # this is the -P, --prereqs flag from Rake
  bin/rails app:template
      environment
  bin/rails app:templates:copy
  bin/rails app:update
      update:configs
      update:bin
      update:active_storage
      update:upgrade_guide_info
  bin/rails app:update:active_storage
  bin/rails app:update:bin

After

In Rails 7.2, the app:update task has been customized into a Rails command which allows the app:update command to support the same generic options as other Rails generators.

The command-line flags includes:

  • --force: Accept all changes to existing files
  • --skip: Refuse all changes to existing files
  • --pretend: Don’t make any changes
  • --quiet: Don’t output all changes made

Running the bin/rails app:update command is now more streamlined. By default, this command will check for updates and prompt us to confirm each change.

Here’s how we can run it:

bin/rails app:update

To accept all changes without confirmation, we can use the –force flag:

bin/rails app:update --force

This makes the update process faster especially in large projects.

Conclusion

The change in app:update to be a Rails command in Rails 7.2 simplifies the update process and aligns it with other Rails generators, providing a consistent and powerful experience.

By using the new command-line flags, we can customize the update process to fit our needs, saving time and reducing the risk of errors.

Need help on your Ruby on Rails or React project?

Join Our Newsletter