fumihumiのブログ

プログラミングの備忘録

undefined method `load_defaults' てなった

railstutorialを始めようとして"rails s " した時に死んだメモ

 undefined method `load_defaults' てなった

実行時エラーは下記。

```

fumihumi:toy_app (master)$ rails sfumihumi:toy_app (master)$ rails s
/Users/fumihumi/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `load_defaults' for #<Rails::Application::Configuration:0x007f96482e2f80> (NoMethodError) from /Users/fumihumi/project/toy_app/config/application.rb:12:in `<class:Application>' from /Users/fumihumi/project/toy_app/config/application.rb:10:in `<module:ToyApp>' from /Users/fumihumi/project/toy_app/config/application.rb:9:in `<top (required)>' from /Users/fumihumi/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:88:in `require' from /Users/fumihumi/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:88:in `block in server' from /Users/fumihumi/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:85:in `tap' from /Users/fumihumi/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:85:in `server' from /Users/fumihumi/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:49:in `run_command!' from /Users/fumihumi/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands.rb:18:in `<top (required)>' from /Users/fumihumi/project/toy_app/bin/rails:9:in `require' from /Users/fumihumi/project/toy_app/bin/rails:9:in `<top (required)>' from /Users/fumihumi/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load' from /Users/fumihumi/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call' from /Users/fumihumi/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call' from /Users/fumihumi/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run' from /Users/fumihumi/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>' from /Users/fumihumi/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load' from /Users/fumihumi/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>' from /Users/fumihumi/.rbenv/versions/2.3.4/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in `require' from /Users/fumihumi/.rbenv/versions/2.3.4/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in `require' from /Users/fumihumi/project/toy_app/bin/spring:15:in `<top (required)>' from bin/rails:3:in `load' from bin/rails:3:in `<main>'

```

load defaultsがない。。。。

ただここまでで実行したのは

1. rails new

2. rbenv local 2.3.4

3. bundle install 

をしただけで"load defaults"なんていじっていない。。

 

では"rake"コマンドができるのかどうか確認したところ

```

rake aborted!
NoMethodError: undefined method `load_defaults' for #<Rails::Application::Configuration:0x007f7fc86dfd68>
/Users/fumihumi/project/toy_app/config/application.rb:12:in `<class:Application>'
/Users/fumihumi/project/toy_app/config/application.rb:10:in `<module:ToyApp>'
/Users/fumihumi/project/toy_app/config/application.rb:9:in `<top (required)>'
/Users/fumihumi/project/toy_app/Rakefile:4:in `require_relative'
/Users/fumihumi/project/toy_app/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

```

 rake aborted.......

これもできない。。。。

 > NoMethodError: undefined method `load_defaults' for #

全く同じですね。。。

 

 

結論

config/application.rbの中の

 > config.load_defaults 5.1

こいつが悪いみたい。

なのでこれをコメントアウトしてやる

> #config.load_defaults 5.1 

```

fumihumi:toy_app (master *)$ rake
Run options: --seed 63099

# Running:

```

はい治った。

 

という訳で

config.load_defaults 5.1

ですがこれはrails 5.1系からできたものみたいで、、、

rails 5.0.3系を使っていた自分はこのエラーになったようです。