Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading Rails: What am I to do with new_framework_defaults file?

I am upgrading from rails 5.1 to 5.2. I did bundle update rails (plus some dependencies) and rails app:update. Now i have the file initializers/new_framework_defaults_5_2.rb, with all lines are commented out.

I am not sure what I need to do now. My app works normally, so I guess, with all lines are commented out I am already on all new defaults. Then I do not need that file, right?

Suppose I run into errors, the values set in the files are the new defaults? So I would uncomment, maybe flip the boolean and try to find out what caused the error?

thank you for your help

like image 322
telzul Avatar asked Apr 30 '18 14:04

telzul


1 Answers

(Having just gone through a 4.2 to 5.2 Rails upgrade, I'll write a more complete answer.)

Rails 5.0

Starting with Rails 5, the Rails team decided to generate an initializer, config/initializers/new_framework_defaults.rb, that contained values for new configuration defaults. This file is generated for both new (rails new) Rails 5.0 applications and applications updated (rake app:update) to Rails 5.0, although the contents differ between new and updated apps.

For new projects, it contains defaults for Rails 5.0.

For updated projects, it contains defaults for the previous version. The intent is that your application will run with the same defaults it had before, and you can toggle/update one at a time during your upgrade.

Rails 5.1 and 5.2

After some shortcomings of this mechanism became apparent (mostly related to the execution of initializers in lexical order), Rails 5.1 made some changes to it.

A new method, #load_defaults, has been added to Rails.application.config. The new framework defaults initializer is versioned, e.g., new_framework_defaults_5_1.rb, and it is only generated during an update, not for a new application.

Unlike the new_framework_defaults.rb from Rails 5.0, settings in the new_framework_defaults_5_x.rb files are (almost) all commented-out. They are the new defaults. You can go through each of them, uncomment the setting, and test your application. If your application runs correctly on the new defaults, you can discard the new_framework_defaults_5_x.rb file and bump the value in config/application.rb to the current version, i.e., change config.load_defaults 5.1 to config.load_defaults 5.2 if you were updating to Rails 5.2.

It's possible there is a setting for which you don't want the new default. If I wanted to make such a setting permanent, I'd probably move it into config/application.rb somewhere below the load_defaults call for all environments, or in the appropriate config/environments/*.rb file(s) for environment-specific configurations.

Summary

It seems to me like the config/initializers/new_framework_defaults*.rb files should not exist after successfully completing an upgrade. They're just there to help highlight changes and aid upgrading from one version to the next.

like image 181
Steve Avatar answered Oct 21 '22 13:10

Steve