I want to upgrade from Rails 5.0 series to Rails 5.2 series. (I wanted to use Active Storage that has been available since Rails 5.2.)
The purpose of this article is to introduce ** the steps required to upgrade from Rails 5.0 series to Rails 5.2 series ** and ** error handling ** that occurred at that time (and I want to use Active Storage). ).
Ruby 2.5.1 Rails 184.108.40.206
I greatly referred to Mr. Ito's Qiita article. Permanent preservation version! ?? Mr. Ito's Rails App Upgrade Procedure
Basically, it is easy to understand if you look at Mr. Ito's article (falling over). However, I think that there are quite a few people who say, "I want to upgrade the version as soon as possible !!", so I hope you can see it in an evil way.
Also, it should cover up to the test, but this time ** the purpose is to use Active Storage **, so I will omit that.
If you upgrade the version of Rails itself first, peripheral gems such as Devise and Carrierwave are not compatible with the latest Rails, and unexpected errors may occur.
Yes. It just happened. Lol
#Run in the directory of the corresponding app $ bundle update -g development -g test
bundle outdated command will list the gems that are out of date.
However, if the number of gems is not so large, you may update it all at once.
If you want to update one by one, specify the gem name after
#When you want to update only devise $ bundle update devise
bundle update without specifying a gem name.
#Leave the Rails version specification unchanged gem 'rails', '~> 5.0.7', '>= 220.127.116.11'
After confirming that the Rails version is specified,
#Update gems in bulk $ bundle update
Change the Rails version specification in the Gemfile to
bundle update rails.
# gem 'rails', '~> 5.0.7', '>= 18.104.22.168' gem 'rails', '~> 5.2.4', '>= 22.214.171.124'
$ bundle update rails
Then run the rails app: update task. Perform this task to interactively create new files or modify existing files as required by the new version.
$ rails app:update conflict config/boot.rb Overwrite config/boot.rb? (enter "h" for help) [Ynaqdhm]
As mentioned above, it is a task to check one by one how to handle files that cause conflicts. Answer with one of the keys Y / n / a / q / d / h.
Y -Yes. Overwrite execution n -No. Do not overwrite a -All. Overwrite all files after this file q -Quit. Processing interruption d -Diff. Show diffs of old and new files h -Help. Show the meaning of each key you enter
Yes, I thought so too and ran ʻa
= all. Thenroutes.rb` was reborn (Hakujitsu).
** Make sure to check only
routes.rb! Rather, let's make it
n! !! ** **
Mr. Ito also said this.
I often check d = diff and then type Y or n. (But most of the Y may be entered except for routes.rb)
Other than that, you need to check the test code and see it with your own eyes, but this time I will aim for
rails s (start the server in the development environment for the time being).
When I triumphantly
rails s, first of all, from this error.
require': cannot load such file --error with bootsnap / setup (LoadError).
$ rails s Traceback (most recent call last): 3: from bin/rails:3:in `<main>' 2: from bin/rails:3:in `require_relative' 1: from /myapp/config/boot.rb:4:in `<top (required)>' ~~~config/boot.rb:4:in `require': cannot load such file -- bootsnap/setup (LoadError)
I was able to respond by this method. There are two changes (files).
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. #Delete this line ↓ (or comment out) require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
~ #Comment out this line ↓ # ActiveSupport.halt_callback_chains_on_return_false = false ~
When I thought "Now, it's time to start the server!" And
rails s, I got an error again.
<top (required)>': undefined methodhalt_callback_chains_on_return_false=' for ActiveSupport:Module (NoMethodError)`
#### **`terminal`** ```terminal => Booting Puma => Rails 126.96.36.199 application starting in development => Run `rails server -h` for more startup options Exiting Traceback (most recent call last): ~~~/config/initializers/new_framework_defaults.rb:23:in `<top (required)>': undefined method `halt_callback_chains_on_return_false=' for ActiveSupport:Module (NoMethodError)
I was able to respond here.
~ #This line ↓ Comment out # Rails.application.config.action_controller.raise_on_unfiltered_parameters = true ~
The error I encountered this time is exactly what Mr. Ito said, so I think it will be useful in the future if you read and understand this article.
As the version of Rails goes up, new behavior that is different from the conventional behavior may be introduced. Ideally, after the version upgrade, everything will be adapted to the new behavior, but in some cases it may be necessary to adapt some behavior to the old Rails.
These behavior changes are made in load_defaults and new_framework_defaults_x_x.rb.
The relationship between load_defaults and new_framework_defaults_x_x.rb is explained in detail in the following article, so please read this and change the settings appropriately.
This completes the Rails version upgrade.
If the above steps don't work, try restarting the server (quit with
ctrl + c, start with
The file that defines environment variables was
secrets.yml in Rails 5.0 series, but it is common to use
master.key in Rails 5.2 series and later.
I thought that it would be possible to make it without permission by upgrading the version of Rails, but there was no such delicious story.
In the first place,
master.key should be created at the time of
rails new, so it is natural to say that ...
Especially the environment variable file worked without tampering. Lol