[RUBY] [Rails] Rails version upgrade error memorandum

Nice to meet you. It is a light fat of the back-end engineer of LCL, Inc. This time it's a company advent calendar, so I'd like to write a memorandum about the Rails version upgrade that I'm doing at work recently. Currently, our service is running on Rails 4,5 series at the beginning, and in this article, I would like to share the problems that I encountered while trying to upgrade to 6.0, 6.1.

table of contents

1. Configuration file system 2. Code change system 3. Others 4. Abolished gems, etc. 5.mac

Configuration file system

1. halt_callback_chains_on_return_false error

error


:this! (new line)
<top (required)>': undefined method `halt_callback_chains_on_return_false=' for ActiveSupport:Module (NoMethodError)`

In Rails 4.2, if "before" type callback returns false in Active Record or Active Model, all callback chains will stop. In this case, the "before" callback will not be executed after that, and the action wrapped in the callback will not be executed either. Rails 5.0 fixes this side effect so that Active Record and Active Model callbacks no longer stop the callback chain when false is returned. Instead, the callback chain will now have to be explicitly stopped at throw (: abort).

How to fix ↓

initializers/new_framework_defaults.rb


#ActiveSupport.halt_callback_chains_on_return_false = true
#Comment out the above

2. error in raise_on_unfiltered_parameters

error


this error: Invalid option key: raise_on_unfiltered_parameters= (RuntimeError)

Specify path parameters: controller and: action as deprecated. (Pull Request) Deprecated config.action_controller.raise_on_unfiltered_parameters. Already disabled in Rails 5.1.

How to fix ↓

initializers/new_framework_defaults.rb


#Rails.application.config.action_controller.raise_on_unfiltered_parameters = true
#Comment out the above

Code change system

1. Arel :: Nodes :: Exists does not work on rails6

The calling method has changed, so please add arel before exists.

Changed to


Hoge.get_hogehoge.where(condition).select('1').exists
↓
Hoge.get_hogehoge.where(condition).select('1').arel.exists

2. join_sources error

error


undefined method `join_sources' for #<CmsArticle::ActiveRecord_Relation:0x00007f8c7c1c8670>

How to fix ↓

python


hoge.join_sources
  ↓
hoge.arel.join_sources

3. String is no longer supported for: if and: unless

error


Passing string to be evaluated in :if and :unless conditional options is not supported. Pass a symbol for an instance method, or a lambda, proc or block, instead.

How to fix ↓

python


Use blocks and lambdas as they are.
☓ if: 'mail.blank?'
○ if: proc { |s| s.mail.blank? }

4. where.not was acting as NOR is now deprecate. Rails 6.1 now works as NAND.

error


>> Post.where.not(source_type: "Feed", source_id: 100)
DEPRECATION WARNING: NOT conditions will no longer behave as NOR in Rails 6.1. To continue using NOR conditions, NOT each conditions manually (`.where.not(:source_type => ...).where.not(:source_id => ...)`). (called from irb_binding at (irb):1)
=> #<ActiveRecord::Relation []>

How to fix ↓

Divide not into multiple


>> Post.where.not(source_type: "Feed").where.not(source_id: 100)

5. From Rails 5.2, class_name: that is not quoted is not accepted.

error


ActionView::Template::Error - A class was passed to `:class_name` but we are expecting a string.:

How to fix ↓

python


   :class_name => ExternalLink
    ↓
   class_name: ‘ExternalLink’

6. Where the array is created in the error message

error


undefined method `[]=' for #<ActiveModel::Errors:0x00007fe7a68ddfe8>
Did you mean?  []

How to fix ↓

Fix


@info_article.errors[:success] =‘The article was updated’
        ↓
@info_article.errors.add(:success,“Updated article”)

7. Change how to use delete_all

error


wrong number of arguments (given 1, expected 0)

Change to where with delete_all at the end

How to fix ↓

Fix


Test.where(article_id: id).joins(:keyword).delete_all(['name NOT IN (?)', keywords])
   ↓
Test.where(article_id: id).joins(:keyword).where("cms_keywords.name not in (?)", keywords).delete_all

8. where_values ​​is no longer available

error


undefined method `where_values' for #<Bus::ActiveRecord_Relation:0x00007fc67f96ae40>
Did you mean?  where_values_hash

How to fix ↓

Fix


where(@buses.where_values.reduce(:and))
  ↓
where(@buses.where_clause.send(:predicates).reduce(:and))

9. manifest error

error


bundle/ruby/2.7.0/gems/sprockets-rails-3.2.1/lib/sprockets/railtie.rb:105:in `block in <class:Railtie>': Expected to find a manifest file in `app/assets/config/manifest.js` (Sprockets::Railtie::ManifestNeededError)
But did not, please create this file and use it to link any assets that need
to be rendered by your app:
Example:
  //= link_tree ../images
  //= link_directory ../javascripts .js
  //= link_directory ../stylesheets .css
and restart your server

How to fix ↓

python


app/assets/config/manifest.create js

10. before_filter is abolished

error


ERROR NoMethodError: undefined method `before_filter' for ApplicationController:Class\nDid you mean?  before_action

How to fix ↓

python


before_filter → before_action

11. About the device for method

error


undefined method `for' for #<Devise::ParameterSanitizer:0x00007fade3ba93c8>

Change for to permit https://github.com/heartcombo/devise#strong-parameters

How to fix ↓

python


    devise_parameter_sanitizer.for(:sign_up) { |u|
      u.permit(:login_id, :email, :password, :password_confirmation)
    }
                   ↓
    devise_parameter_sanitizer.permit(:sign_up) do |user_params|
      user_params.permit(:login_id, :email, :password, :password_confirmation)
    end

12. The datepicker path has changed

error


Sprockets::FileNotFound: couldn't find file 'jquery-ui/datepicker' with type 'application/javascript'
Checked in these paths

How to fix ↓

app/assets/javascripts/application.js


//= require jquery-ui/datepicker
  ↓
//= require jquery-ui/widgets/datepicker

13. Source Directive Addition error

error


Ambiguous source reflection for through association. Please specify a :source directive on your declaration like:
  class GGGG < ActiveRecord::Base
    has_many :payment_methods, {:through=>:hoge_payment_methods, :source=>"payment_method"}
  end

How to fix ↓

python


Add source
-  has_many :payment_methods, :through => :hoge_payment_methods
+  has_many :payment_methods, {:through=>:hoge_payment_methods, :source=>“payment_method”}

Other system

1. Factory_bot data format error

error


undler: failed to load command: unicorn_rails (/Users/goshi/work/busportal-navi/vendor/bundler/ruby/2.7.0/bin/unicorn_rails)
NoMethodError: undefined method ‘booking_site_bus_id’ in ‘promotion_bus’ factory
Did you mean? ‘booking_site_bus_id { 0 }’

All factory_bot data must be enclosed in {}

How to fix ↓

spec/factories/Less than


-  booking_site_bus_id 0
+  booking_site_bus_id {0}

2. rails s can no longer be done

error


vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `require': cannot load such file -- hashie/hash (LoadError)

Add the following and bundle install

How to fix ↓

Gemfile


gem ‘hashie’

Abolished gem etc.

  1. alias_method_chain is deprecated Although alias_method_chain can no longer be used, it was used only in the foreiner gem in this branch.

Reference: gem for einer

Obsolete in rails4.2 and supports foreign keys from rails5.1

Reference: gem foreign key support

2. kakurenbo cannot be used

error


vendor/bundle/ruby/2.7.0/gems/kakurenbo-0.2.3/lib/kakurenbo/mixin_ar_associations.rb:6:in `block in included': undefined method `alias_method_chain' for ActiveRecord::Associations::Association:Class (NoMethodError)
Did you mean?  alias_method

How to fix ↓

python


#gem ‘kakurenbo’ comment out

mac edition

1. pg error

error


An error occurred while installing therubyracer (0.12.3), and Bundler cannot continue.
Make sure that `gem install therubyracer -v '0.12.3' --source 'https://rubygems.org/'` succeeds before
bundling.

How to fix ↓

Terminal command


brew install postgresql

2. pg error 2

error


Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
    current directory: bundler/ruby/2.7.0/gems/pg-1.2.3/ext
.rbenv/versions/2.7.2/bin/ruby -I .rbenv/versions/2.7.2/lib/ruby/2.7.0 -r
./siteconf20201125-58852-173m77x.rb extconf.rb --with-pg-config\=/usr/local/Cellar/postgresql/12.3_4/bin/pg_config
Using config values from /usr/local/Cellar/postgresql/12.3_4/bin/pg_config
sh: /usr/local/Cellar/postgresql/12.3_4/bin/pg_config: No such file or directory
sh: /usr/local/Cellar/postgresql/12.3_4/bin/pg_config: No such file or directory

How to fix ↓

Terminal command


$ which pg_config
  /usr/local/bin/pg_config
$ bundle config build.pg  --with-pg-config=/usr/local/bin/pg_config

3. error in therubyracer, libv8

error


An error occurred while installing therubyracer (0.12.3), and Bundler cannot continue.
Make sure that `gem install therubyracer -v '0.12.3' --source 'https://rubygems.org/'` succeeds before
bundling.

It seems to happen because the mac default gcc is old

Newly install gcc and change path Add settings to .bundle/config bundle install

How to fix ↓

Terminal command


brew install gcc
ln -s /usr/local/bin/gcc-9 /usr/local/bin/gcc
ln -s /usr/local/bin/g++-9  /usr/local/bin/g++
brew install v8-315

.bundle/Edit config


---
BUNDLE_BUILD__LIBV8: "--with-system-v8"
BUNDLE_BUILD__THERUBYRACER: "--with-v8-dir=/usr/local/opt/[email protected]"

4. rugged error

error


An error occurred while installing rugged (1.0.0), and Bundler cannot continue.
Make sure that `gem install rugged -v '1.0.0' --source 'https://rubygems.org/'` succeeds before bundling.

It seems to be fixed by adding cmake

How to fix ↓

Terminal command


brew reinstall gcc
brew install cmake

5. nokogiri error

error


Installing nokogiri 1.10.10 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
    current directory: vendor/bundler /ruby/2.7.0/gems/nokogiri-1.10.10/ext/nokogiri
/Users/goshi/.rbenv/versions/2.7.2/bin/ruby -I /Users/goshi/.rbenv/versions/2.7.2/lib/ruby/2.7.0 -r
./siteconf20201125-45870-1adiffq.rb extconf.rb
checking if the C compiler accepts  -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
Using mini_portile version 2.4.0
checking for iconv.h... yes
checking for gzdopen() in -lz... yes
checking for iconv... yes
************************************************************************
IMPORTANT NOTICE:
Building Nokogiri with a packaged version of libxml2-2.9.10
with the following patches applied:
	- 0001-Revert-Do-not-URI-escape-in-server-side-includes.patch
	- 0002-Remove-script-macro-support.patch
	- 0003-Update-entities-to-remove-handling-of-ssi.patch
	- 0004-libxml2.la-is-in-top_builddir.patch
	- 0005-Fix-infinite-loop-in-xmlStringLenDecodeEntities.patch
Team Nokogiri will keep on doing their best to provide security
updates in a timely manner, but if this is a concern for you and want
to use the system library instead; abort this installation process and
reinstall nokogiri as follows:

How to fix ↓

Terminal command


bundle config build.nokogiri --use-system-libraries
Then bundle install

Recommended Posts

[Rails] Rails version upgrade error memorandum
Rails version upgrade memorandum 5.0 → 5.1
Rails memorandum
Project ruby and rails version upgrade
Rails tutorial memorandum 1
Rails tutorial memorandum 2
Catch Rails Routing Error
About rails version specification
[Rails error] unexpected tIDENTIFIER
Mac Rails Install Error
rails heroku error log
Rails Tutorial Memorandum (Chapter 3, 3.1)
rails error resolution summary
[Rails version control] rails version downgrade
CentOS 7 curl version upgrade
Rails Tutorial Memorandum (Chapter 3, 3.3.2)
[Memorandum] What is an error?
rails error Library not loaded
Rails Tutorial Records and Memorandum # 0
Error in rails db: migrate
Error when using rails capybara
[rails] error during devise installation
Ruby on Rails Basic Memorandum
Memorandum [Rails] User authentication Devise
I get a Ruby version error when I try to start Rails.
[Rails] What was the error message?
[Rails] Unexpected validation error in devise
[Rails] Display form error messages asynchronously
[Grover] Generate PDF with Rails [2020 version]
Error handling in gRPC (Kotlin version)
Japanese localization of error messages (rails)
Error summary in bundle install. memorandum
Spring thorough introduction version upgrade memo
[Rails] syntax error, unexpected tSTRING_END, expecting'''
[Rails] AWS deployment error encounter summary
Ruby on Rails [Error memorandum] Routing Error No route matches [DELETE] "/ users / sign_out"
Rails Tutorial record and memorandum # 1 "From installation to hello_app deployment + error handling"