現象
Ruby 3.1.0がリリースされた直後にRails 7.0.0をRuby 3.1.0で動かそうとすると、以下のRails::Engine is abstract, you cannot instantiate it directly.
エラーが出て動きませんでした。これはrails new
の場合ですが、他の操作でも出ました。
$ dip rails new . --skip-git
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
exist
conflict README.md
Overwrite /app/README.md? (enter "h" for help) [Ynaqdhm] n
skip README.md
create Rakefile
conflict .ruby-version
Overwrite /app/.ruby-version? (enter "h" for help) [Ynaqdhm] n
skip .ruby-version
create config.ru
conflict Gemfile
Overwrite /app/Gemfile? (enter "h" for help) [Ynaqdhm] y
force Gemfile
create app
create app/assets/config/manifest.js
create app/assets/stylesheets/application.css
create app/channels/application_cable/channel.rb
create app/channels/application_cable/connection.rb
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/jobs/application_job.rb
create app/mailers/application_mailer.rb
create app/models/application_record.rb
create app/views/layouts/application.html.erb
create app/views/layouts/mailer.html.erb
create app/views/layouts/mailer.text.erb
create app/assets/images
create app/assets/images/.keep
create app/controllers/concerns/.keep
create app/models/concerns/.keep
create bin
create bin/rails
create bin/rake
create bin/setup
create config
create config/routes.rb
create config/application.rb
create config/environment.rb
create config/cable.yml
create config/puma.rb
create config/storage.yml
create config/environments
create config/environments/development.rb
create config/environments/production.rb
create config/environments/test.rb
create config/initializers
create config/initializers/assets.rb
create config/initializers/content_security_policy.rb
create config/initializers/cors.rb
create config/initializers/filter_parameter_logging.rb
create config/initializers/inflections.rb
create config/initializers/new_framework_defaults_7_0.rb
create config/initializers/permissions_policy.rb
create config/locales
create config/locales/en.yml
create config/master.key
create config/boot.rb
create config/database.yml
create db
create db/seeds.rb
create lib
create lib/tasks
create lib/tasks/.keep
create lib/assets
create lib/assets/.keep
create log
create log/.keep
create public
create public/404.html
create public/422.html
create public/500.html
create public/apple-touch-icon-precomposed.png
create public/apple-touch-icon.png
create public/favicon.ico
create public/robots.txt
exist tmp
create tmp/.keep
create tmp/pids
create tmp/pids/.keep
exist tmp/cache
create tmp/cache/assets
create vendor
create vendor/.keep
create test/fixtures/files
create test/fixtures/files/.keep
create test/controllers
create test/controllers/.keep
create test/mailers
create test/mailers/.keep
create test/models
create test/models/.keep
create test/helpers
create test/helpers/.keep
create test/integration
create test/integration/.keep
create test/channels/application_cable/connection_test.rb
create test/test_helper.rb
create test/system
create test/system/.keep
create test/application_system_test_case.rb
create storage
create storage/.keep
create tmp/storage
create tmp/storage/.keep
remove config/initializers/cors.rb
remove config/initializers/new_framework_defaults_7_0.rb
run bundle install
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Using rake 13.0.6
Using concurrent-ruby 1.1.9
Using minitest 5.15.0
Using builder 3.2.4
Using erubi 1.10.0
Using crass 1.0.6
Using rack 2.2.3
Using mini_portile2 2.6.1
Using nio4r 2.5.8
Using marcel 1.0.2
Using mini_mime 1.1.2
Fetching public_suffix 4.0.6
Fetching bindex 0.8.1
Using websocket-extensions 0.1.5
Using racc 1.6.0
Fetching msgpack 1.4.2
Using bundler 2.3.3
Fetching matrix 0.4.2
Installing bindex 0.8.1 with native extensions
Installing matrix 0.4.2
Installing msgpack 1.4.2 with native extensions
Installing public_suffix 4.0.6
Fetching regexp_parser 2.2.0
Installing regexp_parser 2.2.0
Fetching childprocess 4.1.0
Fetching io-console 0.5.11
Installing io-console 0.5.11 with native extensions
Installing childprocess 4.1.0
Using method_source 1.0.0
Using thor 1.1.0
Using zeitwerk 2.5.3
Fetching rexml 3.2.5
Installing rexml 3.2.5
Fetching rubyzip 2.3.2
Fetching sqlite3 1.4.2
Installing rubyzip 2.3.2
Installing sqlite3 1.4.2 with native extensions
Using i18n 1.8.11
Using tzinfo 2.0.4
Using rack-test 1.1.0
Using mail 2.7.1
Fetching puma 5.5.2
Installing puma 5.5.2 with native extensions
Fetching sprockets 4.0.2
Installing sprockets 4.0.2
Using websocket-driver 0.7.5
Using nokogiri 1.12.5
Fetching addressable 2.8.0
Fetching selenium-webdriver 4.1.0
Installing addressable 2.8.0
Using activesupport 7.0.0
Fetching reline 0.3.1
Installing selenium-webdriver 4.1.0
Using loofah 2.13.0
Fetching xpath 3.2.0
Installing reline 0.3.1
Using rails-dom-testing 2.0.3
Using globalid 1.0.0
Using activemodel 7.0.0
Fetching webdrivers 5.0.0
Installing xpath 3.2.0
Using rails-html-sanitizer 1.4.2
Using irb 1.4.1
Using activejob 7.0.0
Using activerecord 7.0.0
Fetching capybara 3.36.0
Installing webdrivers 5.0.0
Using actionview 7.0.0
Fetching debug 1.4.0
Installing capybara 3.36.0
Installing debug 1.4.0 with native extensions
Using actionpack 7.0.0
Fetching jbuilder 2.11.5
Installing jbuilder 2.11.5
Using actioncable 7.0.0
Using activestorage 7.0.0
Using actionmailer 7.0.0
Using railties 7.0.0
Fetching sprockets-rails 3.4.2
Installing sprockets-rails 3.4.2
Using actionmailbox 7.0.0
Using actiontext 7.0.0
Fetching importmap-rails 1.0.1
Installing importmap-rails 1.0.1
Fetching stimulus-rails 1.0.2
Installing stimulus-rails 1.0.2
Fetching turbo-rails 1.0.0
Fetching web-console 4.2.0
Installing web-console 4.2.0
Installing turbo-rails 1.0.0
Using rails 7.0.0
Fetching bootsnap 1.9.3
Installing bootsnap 1.9.3 with native extensions
Bundle complete! 15 Gemfile dependencies, 67 gems now installed.
Bundled gems are installed into `/bundle`
run bundle binstubs bundler
Skipped bundle since it already exists.
If you want to overwrite skipped stubs, use --force.
rails importmap:install
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
rails aborted!
Rails::Engine is abstract, you cannot instantiate it directly.
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/railtie.rb:246:in `initialize'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/railtie.rb:184:in `new'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/railtie.rb:184:in `instance'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/railtie.rb:223:in `method_missing'
/bundle/ruby/3.1.0/gems/activesupport-7.0.0/lib/active_support/descendants_tracker.rb:90:in `descendants'
/bundle/ruby/3.1.0/gems/activesupport-7.0.0/lib/active_support/callbacks.rb:923:in `block in define_callbacks'
/bundle/ruby/3.1.0/gems/activesupport-7.0.0/lib/active_support/callbacks.rb:920:in `each'
/bundle/ruby/3.1.0/gems/activesupport-7.0.0/lib/active_support/callbacks.rb:920:in `define_callbacks'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/engine.rb:427:in `<class:Engine>'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/engine.rb:349:in `<module:Rails>'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/engine.rb:11:in `<main>'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/application.rb:11:in `<main>'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails.rb:13:in `<main>'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/all.rb:5:in `<main>'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/app/config/application.rb:3:in `<main>'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `require_relative'
/app/rakefile:4:in `<main>'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:60:in `load'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:60:in `load'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/commands/rake/rake_command.rb:20:in `block in perform'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/command.rb:51:in `invoke'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/commands.rb:18:in `<main>'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
bin/rails:4:in `<main>'
(See full trace by running task with --trace)
rails turbo:install stimulus:install
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
rails aborted!
Rails::Engine is abstract, you cannot instantiate it directly.
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/railtie.rb:246:in `initialize'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/railtie.rb:184:in `new'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/railtie.rb:184:in `instance'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/railtie.rb:223:in `method_missing'
/bundle/ruby/3.1.0/gems/activesupport-7.0.0/lib/active_support/descendants_tracker.rb:90:in `descendants'
/bundle/ruby/3.1.0/gems/activesupport-7.0.0/lib/active_support/callbacks.rb:923:in `block in define_callbacks'
/bundle/ruby/3.1.0/gems/activesupport-7.0.0/lib/active_support/callbacks.rb:920:in `each'
/bundle/ruby/3.1.0/gems/activesupport-7.0.0/lib/active_support/callbacks.rb:920:in `define_callbacks'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/engine.rb:427:in `<class:Engine>'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/engine.rb:349:in `<module:Rails>'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/engine.rb:11:in `<main>'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/application.rb:11:in `<main>'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails.rb:13:in `<main>'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/all.rb:5:in `<main>'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/app/config/application.rb:3:in `<main>'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `require_relative'
/app/rakefile:4:in `<main>'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:60:in `load'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:60:in `load'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/commands/rake/rake_command.rb:20:in `block in perform'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/command.rb:51:in `invoke'
/bundle/ruby/3.1.0/gems/railties-7.0.0/lib/rails/commands.rb:18:in `<main>'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/bundle/ruby/3.1.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
bin/rails:4:in `<main>'
(See full trace by running task with --trace)
原因
2021年12月はRails 7.0.0が先にリリースされ、その後でRuby 3.1がリリースされました。Rails 7.0.0ではRuby 3.1.0の新機能であるClass#descendants
をいち早く取り入れていました。しかしClass#descendants
はRuby 3.1リリース直前にMatzの意向で仕様再検討のためいったん削除された(#5309)、という流れのようです。それによってRails 7のClass#descendants
に依存している部分がエラーになったようです。
上のプルリクはClass#descendants
への依存をRails 7から削除します。これはmainブランチと7-0-stableブランチにはマージ済みで、今後Rails 7.0.1に含まれる見込みです。
現時点の解決方法
既に@yahondaさんが解決方法や詳しい解説をgistにまとめてくださっています🙏。正直、ここを見れば必要なことはわかります。
- Gist: Ruby 3.1 on Rails
同Gistにもあるように、Rails 7.0.0をRuby 3.1で動かすには、Gemfileで7-0-stableブランチを指定する必要があります(この場合以下のようにリポジトリ名も指定する必要があります)。今後はRails 7.0.1がリリースされれば解消されるはずです。
# Gemfile
gem "rails", github: "rails/rails", branch: "7-0-stable"
なお、rails new
の場合は、事前にbundle init
で生成したGemfileで上のように7-0-stableブランチを指定しておいても、Gemfileが更新されるときに以下のようにデフォルトの7.0.0で上書きされてしまうので、上の現象が再発しました。
# Gemfile
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.1.0"
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.0"
# ...
私の場合は、このGemfileだけいったん残して他の生成ファイルを削除し、Gemfileを以下のようにgem "rails", github: "rails/rails", branch: "7-0-stable"
に変更してbundle install
してから、改めてrails new
するという方法で無理やり回避しました。
# Gemfile
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.1.0"
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", github: "rails/rails", branch: "7-0-stable"
# ...
参考: Ruby 3.1.0向けの設定
Ruby 3.1.0のYJITを有効にするには、環境変数RUBY_YJIT_ENABLE=1
を設定するか、起動時に--yjit
オプションを追加します。
また、Rails 7.0.0ではconfig/application.rbでconfig.active_support.disable_to_s_conversion
を設定すると、Ruby 3.1.0で最適化された式展開を有効にするために
= trueto_s
を上書きしなくなります。
参考: thorのwarningについて
上の問題とは別に、以下のdeprecation warningがthor gemで発生していました。
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
Ruby 3.1環境でyamlを扱うさまざまな場所でこのwarningが表示されます。thorはRailsリポジトリにあるgemですが、Rails以外でも使われていることがあります。
私の場合は、以下のdipツールで上のwarningが出るようになりました。影響があるわけではありませんが、ちょっと目障りですね。
昨年末に以下のプルリクが上がっていましたが、つい今朝がたマージされました🎉。gem update
でthorを更新するとdipでもwarningが発生しなくなりました。
追記(2022/01/07)
本記事で取り上げている問題は、Rails 7.0.1で修正されました。