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.
1. Configuration file system 2. Code change system 3. Others 4. Abolished gems, etc. 5.mac
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).
initializers/new_framework_defaults.rb
#ActiveSupport.halt_callback_chains_on_return_false = true
#Comment out the above
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.
initializers/new_framework_defaults.rb
#Rails.application.config.action_controller.raise_on_unfiltered_parameters = true
#Comment out the above
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
error
undefined method `join_sources' for #<CmsArticle::ActiveRecord_Relation:0x00007f8c7c1c8670>
python
hoge.join_sources
↓
hoge.arel.join_sources
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.
python
Use blocks and lambdas as they are.
☓ if: 'mail.blank?'
○ if: proc { |s| s.mail.blank? }
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 []>
Divide not into multiple
>> Post.where.not(source_type: "Feed").where.not(source_id: 100)
error
ActionView::Template::Error - A class was passed to `:class_name` but we are expecting a string.:
python
:class_name => ExternalLink
↓
class_name: ‘ExternalLink’
error
undefined method `[]=' for #<ActiveModel::Errors:0x00007fe7a68ddfe8>
Did you mean? []
Fix
@info_article.errors[:success] =‘The article was updated’
↓
@info_article.errors.add(:success,“Updated article”)
error
wrong number of arguments (given 1, expected 0)
Change to where with delete_all at the end
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
error
undefined method `where_values' for #<Bus::ActiveRecord_Relation:0x00007fc67f96ae40>
Did you mean? where_values_hash
Fix
where(@buses.where_values.reduce(:and))
↓
where(@buses.where_clause.send(:predicates).reduce(:and))
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
python
app/assets/config/manifest.create js
error
ERROR NoMethodError: undefined method `before_filter' for ApplicationController:Class\nDid you mean? before_action
python
before_filter → before_action
error
undefined method `for' for #<Devise::ParameterSanitizer:0x00007fade3ba93c8>
Change for to permit https://github.com/heartcombo/devise#strong-parameters
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
error
Sprockets::FileNotFound: couldn't find file 'jquery-ui/datepicker' with type 'application/javascript'
Checked in these paths
app/assets/javascripts/application.js
//= require jquery-ui/datepicker
↓
//= require jquery-ui/widgets/datepicker
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
python
Add source
- has_many :payment_methods, :through => :hoge_payment_methods
+ has_many :payment_methods, {:through=>:hoge_payment_methods, :source=>“payment_method”}
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 {}
spec/factories/Less than
- booking_site_bus_id 0
+ booking_site_bus_id {0}
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
Gemfile
gem ‘hashie’
Reference: gem for einer
Obsolete in rails4.2 and supports foreign keys from rails5.1
Reference: gem foreign key support
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
python
#gem ‘kakurenbo’ comment out
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.
Terminal command
brew install postgresql
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
Terminal command
$ which pg_config
/usr/local/bin/pg_config
$ bundle config build.pg --with-pg-config=/usr/local/bin/pg_config
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
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]"
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
Terminal command
brew reinstall gcc
brew install cmake
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:
Terminal command
bundle config build.nokogiri --use-system-libraries
Then bundle install
Recommended Posts