diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index d132e86ca7ae3..6dd4562656359 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -27,7 +27,7 @@ The process should go as follows: 3. Fix tests and deprecated features. 4. Move to the latest patch version of the next minor version. -Repeat this process until you reach your target Rails version. Each time you move versions, you will need to change the Rails version number in the `Gemfile` (and possibly other gem versions) and run `bundle update`. Then run the Update task mentioned below to update configuration files, then run your tests. +Repeat this process until you reach your target Rails version. Each time you move versions, you will need to change the Rails version number in the `Gemfile` (and possibly other gem versions) and run `bundle update`. Then run the [Update task](#the-update-task) and finally, your tests. You can find a list of all released Rails versions [here](https://rubygems.org/gems/rails/versions). @@ -38,30 +38,21 @@ Rails generally stays close to the latest released Ruby version when it's releas * Rails 7 requires Ruby 2.7.0 or newer. * Rails 6 requires Ruby 2.5.0 or newer. * Rails 5 requires Ruby 2.2.2 or newer. -* Rails 4 prefers Ruby 2.0 and requires 1.9.3 or newer. -* Rails 3.2.x is the last branch to support Ruby 1.8.7. -* Rails 3 and above require Ruby 1.8.7 or higher. Support for all of the previous Ruby versions has been dropped officially. You should upgrade as early as possible. - -TIP: Ruby 1.8.7 p248 and p249 have marshalling bugs that crash Rails. Ruby Enterprise Edition has these fixed since the release of 1.8.7-2010.02. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults, so if you want to use 1.9.x, jump straight to 1.9.3 for smooth sailing. ### The Update Task -Rails provides the `app:update` command (`rake rails:update` on 4.2 and earlier). After updating the Rails version +Rails provides the `rails app:update` command. After updating the Rails version in the `Gemfile`, run this command. This will help you with the creation of new files and changes of old files in an interactive session. ```bash $ bin/rails app:update - identical config/boot.rb exist config - conflict config/routes.rb -Overwrite /myapp/config/routes.rb? (enter "h" for help) [Ynaqdh] - force config/routes.rb conflict config/application.rb Overwrite /myapp/config/application.rb? (enter "h" for help) [Ynaqdh] force config/application.rb - conflict config/environment.rb + create config/initializers/new_framework_defaults_7_0.rb ... ``` @@ -71,7 +62,7 @@ Don't forget to review the difference, to see if there were any unexpected chang The new Rails version might have different configuration defaults than the previous version. However, after following the steps described above, your application would still run with configuration defaults from the *previous* Rails version. That's because the value for `config.load_defaults` in `config/application.rb` has not been changed yet. -To allow you to upgrade to new defaults one by one, the update task has created a file `config/initializers/new_framework_defaults.rb`. Once your application is ready to run with new defaults, you can remove this file and flip the `config.load_defaults` value. +To allow you to upgrade to new defaults one by one, the update task has created a file `config/initializers/new_framework_defaults_X.Y.rb` (with the desired Rails version in the filename). You should enable the new configuration defaults by uncommenting them in the file; this can be done gradually over several deployments. Once your application is ready to run with new defaults, you can remove this file and flip the `config.load_defaults` value. Upgrading from Rails 6.1 to Rails 7.0 ------------------------------------- diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 40b86565308cc..e8ca72796f370 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,9 @@ +* `rails app:update` no longer prompts you to overwrite files that are generally modified in the + course of developing a Rails app. See [#41083](https://github.com/rails/rails/pull/41083) for + the full list of changes. + + *Alex Ghiculescu* + * Change default branch for new Rails projects and plugins to `main`. *Prateek Choudhary* diff --git a/railties/lib/rails/app_updater.rb b/railties/lib/rails/app_updater.rb index 19d136e041b5c..8bc709d21b1f4 100644 --- a/railties/lib/rails/app_updater.rb +++ b/railties/lib/rails/app_updater.rb @@ -13,7 +13,7 @@ def invoke_from_app_generator(method) def app_generator @app_generator ||= begin gen = Rails::Generators::AppGenerator.new ["rails"], generator_options, destination_root: Rails.root - File.exist?(Rails.root.join("config", "application.rb")) ? gen.send(:app_const) : gen.send(:valid_const?) + gen.send(:valid_const?) unless File.exist?(Rails.root.join("config", "application.rb")) gen end end @@ -30,6 +30,7 @@ def generator_options options[:skip_puma] = !defined?(Puma) options[:skip_bootsnap] = !defined?(Bootsnap) options[:skip_spring] = !defined?(Spring) + options[:updating] = true options end end diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index aa160f2e8e555..15a0d153016b8 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -120,17 +120,17 @@ def config empty_directory "config" inside "config" do - template "routes.rb" + template "routes.rb" unless options[:updating] template "application.rb" template "environment.rb" - template "cable.yml" unless options[:skip_action_cable] - template "puma.rb" unless options[:skip_puma] + template "cable.yml" unless options[:updating] || options[:skip_action_cable] + template "puma.rb" unless options[:updating] || options[:skip_puma] template "spring.rb" if spring_install? - template "storage.yml" unless skip_active_storage? + template "storage.yml" unless options[:updating] || skip_active_storage? directory "environments" directory "initializers" - directory "locales" + directory "locales" unless options[:updating] end end @@ -148,7 +148,6 @@ def config_when_updating @config_target_version = Rails.application.config.loaded_config_version || "5.0" config - configru unless cookie_serializer_config_exist gsub_file "config/initializers/cookies_serializer.rb", /json(?!,)/, "marshal"