前提・実現したいこと
Railsの初学者です。現在開発中のアプリをローカル環境で動かしながら作業してしていたところ、rails sコマンドが使えなくなりました。またrails gやrails cも使えなくなっておりエラー文の
(erb):2:in `<main>': undefined method `[]' for nil:NilClass (NoMethodError)
部分を見る限りだとどこが原因となっているのかを自分では特定出来ず調べたりしたのですが、原因が分からずそこから詰まっております。恐れ入りますがどこに解決の糸口があるのかアドバイスをいただけると幸いです。
発生している問題・エラーメッセージ
rails s 実行時(rails g,rails cコマンドでも同様のエラーです) (erb):2:in `<main>': undefined method `[]' for nil:NilClass (NoMethodError) from /Users/.rbenv/versions/3.0.0/lib/ruby/3.0.0/erb.rb:905:in `eval' from /Users/.rbenv/versions/3.0.0/lib/ruby/3.0.0/erb.rb:905:in `result' from /Users/vendor/bundle/ruby/3.0.0/gems/config-3.1.0/lib/config/sources/yaml_source.rb:19:in `load' from /Users/vendor/bundle/ruby/3.0.0/gems/config-3.1.0/lib/config/options.rb:38:in `block in reload!' from /Users/vendor/bundle/ruby/3.0.0/gems/config-3.1.0/lib/config/options.rb:37:in `each' from /Users/vendor/bundle/ruby/3.0.0/gems/config-3.1.0/lib/config/options.rb:37:in `reload!' from /Users/vendor/bundle/ruby/3.0.0/gems/config-3.1.0/lib/config.rb:48:in `load_files' from /Users/vendor/bundle/ruby/3.0.0/gems/config-3.1.0/lib/config.rb:56:in `load_and_set_settings' from /Users/vendor/bundle/ruby/3.0.0/gems/config-3.1.0/lib/config/integrations/rails/railtie.rb:11:in `preload' from /Users/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/railtie.rb:207:in `public_send' from /Users/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/railtie.rb:207:in `method_missing' from /Users/vendor/bundle/ruby/3.0.0/gems/config-3.1.0/lib/config/integrations/rails/railtie.rb:21:in `block in <class:Railtie>' from /Users/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/lazy_load_hooks.rb:68:in `block in execute_hook' from /Users/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control' from /Users/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook' from /Users/hayat/voice_component/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks' from /Users/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/lazy_load_hooks.rb:51:in `each' from /Users/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks' from /Users/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/application.rb:96:in `inherited' from /Users/config/application.rb:24:in `<module:VoiceComponent>' from /Users/config/application.rb:22:in `<main>' from /Users/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' from /Users/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' from /Users/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' from /Users/hayat/voice_component/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' from /Users/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' from /Users/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:332:in `block in require' from /Users/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:299:in `load_dependency' from /Users/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:332:in `require' from /Users/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/commands/server/server_command.rb:138:in `block in perform' from <internal:kernel>:90:in `tap' from /Users/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/commands/server/server_command.rb:135:in `perform' from /Users/vendor/bundle/ruby/3.0.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run' from /Users/vendor/bundle/ruby/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command' from /Users/vendor/bundle/ruby/3.0.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch' from /Users/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/command/base.rb:69:in `perform' from /Users/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/command.rb:50:in `invoke' from /Users/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/commands.rb:18:in `<main>' from /Users/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' from /Users/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' from /Users/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' from /Users/hayat/voice_component/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' from /Users/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' from /Users/bin/rails:5:in `<top (required)>' from /Users/vendor/bundle/ruby/3.0.0/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `load' from /Users/vendor/bundle/ruby/3.0.0/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `call' from /Users/vendor/bundle/ruby/3.0.0/gems/spring-2.1.1/lib/spring/client/command.rb:7:in `call' from /Users/vendor/bundle/ruby/3.0.0/gems/spring-2.1.1/lib/spring/client.rb:30:in `run' from /Users/vendor/bundle/ruby/3.0.0/gems/spring-2.1.1/bin/spring:49:in `<top (required)>' from /Users/vendor/bundle/ruby/3.0.0/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `load' from /Users/vendor/bundle/ruby/3.0.0/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `<top (required)>' from <internal:/Users/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require' from <internal:/Users/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require' from /Users/bin/spring:10:in `block in <top (required)>' from <internal:kernel>:90:in `tap' from /Users/hayat/voice_component/bin/spring:7:in `<top (required)>' from bin/rails:2:in `load' from bin/rails:2:in `<main>'
該当のソースコード
こちらが原因ではないかもしれませんが、補足情報に載せている参考記事にdatabase.ymlが原因ではないかとの記載があったのでこちらを載せます。
ソースコード config/database.yml 2 default: &default 3 adapter: mysql2 4 encoding: utf8mb4 5 charset: utf8mb4 6 collation: utf8mb4_general_ci 7 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 8 username: root 9 password: 10 socket: /tmp/mysql.sock 11 12 development: 13 <<: *default 14 database: Sample_development 15 16 test: 17 <<: *default 18 database: Sample_test 19 20 production: 21 <<: *default 22 database: <%= Rails.application.credentials.db[:database] %> 23 username: <%= Rails.application.credentials.db[:username] %> 24 password: <%= Rails.application.credentials.db[:password] %> 25 host: <%= Rails.application.credentials.db[:host] %> 26
試したこと
$ gem install bundler
を実行し、その後下記を実行
$ bundle install --path vendor/bundle
補足情報(FW/ツールのバージョンなど)
Rails 6.1.3.1 ruby 3.0.0
調べていて似たようなエラーの参考記事があったのですが、これが自分の中で上手く理解しきれておらず、まだこちらは試しておりません。
https://stackoverflow.com/questions/65496869/erb48in-main-undefined-method-for-nilnilclass-nomethoderror
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/06/29 08:51 編集
2021/06/29 09:01
2021/06/30 00:28
2021/06/30 00:56
2021/06/30 01:25
2021/06/30 04:18
2021/06/30 05:09