Solution for errors that occur when upgrading to Rails 5.2 series

Introduction

As a Rails beginner, I have summarized the points I stumbled upon as a memorandum.

Learning materials

Rails engineer training course taught by full stack engineers

Problem ①

The following error occurred when updating the Rails version to 5.2 series with Gemfile and starting the container.

Exiting
web_1  | /app/config/initializers/new_framework_defaults.rb:21:in `<top (required)>': undefined method `halt_callback_chains_on_return_false=' for ActiveSupport:Module (NoMethodError)

Solutions

You can tell by reading the error, It can be read that the cause is the ** halt_callback_chains_on_return_false ** method of /app/config/initializers/new_framework_defaults.rb. After investigating, it seems that halt_callback_chains_on_return_false has been removed from Rails 5.2, so commenting it out can solve the problem.

new_framework_defaults.rb


# Do not halt callback chains when a callback returns false. Previous versions had true.
#ActiveSupport.halt_callback_chains_on_return_false = false <=Comment out

Problem ②

Test with Rspec from command

docker-compose exec web bundle exec rspec ./spec/models/

Then, the following error is output (error excerpt)

rails aborted!
ActiveRecord::MismatchedForeignKey: Column `board_id` on table `board_tag_relations` has a type of `int(11)`.
This does not match column `id` on `boards`, which has type `bigint(20)`.
To resolve this issue, change the type of the `board_id` column on `board_tag_relations` to be :integer. (For example `t.integer board_id`).

Solutions

Before 5.1 series, when migration is created, the id column is created with int by default, but from 5.1 series this is changed to big int. Since FK constraints cannot be set between columns with different types, it is necessary to unify the types.

As a solution, modify board_tag_relations.board_id to int type and db: migrate: reset to solve the problem.

problem

Error occurred in redirect_to: back


redirect_to :back, flash: {
        user: user,
        error_messages: user.errors.full_messages
      }

Solutions

From Rails 5.1 series It has been replaced with redirect_to: back =>redirect_back (fallback_location: root_path), so if you fix it, the problem will be solved.

redirect_back(fallback_location: "http://localhost", 
      flash: {
        user: user,
        error_messages: user.errors.full_messages
      })

reference

Recommended Posts

Solution for errors that occur when upgrading to Rails 5.2 series
How to resolve errors when installing Rails 5.1.3
How to resolve errors that occur in the "Ruby on Rails" integration test
[Ruby] 5 errors that tend to occur when scraping with Selenium and how to deal with them
Avoid the problem that session cannot be acquired when canary release when upgrading from Rails 4.2.x to 5.0.x
A solution to Docker errors that beginners tend to get stuck in
To avoid errors when starting miChecker
[WSL] Solution for the phenomenon that 404 is displayed when trying to insert Java with apt (personal memo)
When you want Rails to disable a session for a specific controller only
Avoid Java encoding errors that occur when running FitGen.exe on Japanese Windows
How to apply Rails environment variables to Docker container (aws :: Sigv4 :: Errors solution)
[Rails] [Memo] When to add = to <%%> and when not
[Solution] Webpacker error when introducing Vuetify to Rails6 "ActionView :: Template :: Error Webpacker can't find hello_vue ~"
Solution that gives an error when trying to connect to DB (MySQL) in Java