Rails console error: undefined `each 'method for nil: NilClass (NoMethodError)

Any attempt to run the rails console in the root directory of my Rails application raises the following error:

undefined `each 'method for nil: NilClass (NoMethodError)

Full stack trace:

  /Users/gnerkus/.rvm/gems/ ruby-2.2.3@rails-experiments /gems/railties-5.0.0.beta1.1/lib/rails/railtie.rb:245:in `each_registered_block': undefined method `each' for nil:NilClass (NoMethodError) from /Users/gnerkus/.rvm/gems/ ruby-2.2.3@rails-experiments /gems/railties-5.0.0.beta1.1/lib/rails/railtie.rb:224:in `run_console_blocks' from /Users/gnerkus/.rvm/gems/ ruby-2.2.3@rails-experiments /gems/railties-5.0.0.beta1.1/lib/rails/application.rb:461:in `block in run_console_blocks' from /Users/gnerkus/.rvm/gems/ ruby-2.2.3@rails-experiments /gems/railties-5.0.0.beta1.1/lib/rails/engine/railties.rb:13:in `each' from /Users/gnerkus/.rvm/gems/ ruby-2.2.3@rails-experiments /gems/railties-5.0.0.beta1.1/lib/rails/engine/railties.rb:13:in `each' from /Users/gnerkus/.rvm/gems/ ruby-2.2.3@rails-experiments /gems/railties-5.0.0.beta1.1/lib/rails/application.rb:461:in `run_console_blocks' from /Users/gnerkus/.rvm/gems/ ruby-2.2.3@rails-experiments /gems/railties-5.0.0.beta1.1/lib/rails/engine.rb:442:in `load_console' from /Users/gnerkus/.rvm/gems/ ruby-2.2.3@rails-experiments /gems/railties-5.0.0.beta1.1/lib/rails/commands/console.rb:34:in `initialize' from /Users/gnerkus/.rvm/gems/ ruby-2.2.3@rails-experiments /gems/railties-5.0.0.beta1.1/lib/rails/commands/console_helper.rb:9:in `new' from /Users/gnerkus/.rvm/gems/ ruby-2.2.3@rails-experiments /gems/railties-5.0.0.beta1.1/lib/rails/commands/console_helper.rb:9:in `start' from /Users/gnerkus/.rvm/gems/ ruby-2.2.3@rails-experiments /gems/railties-5.0.0.beta1.1/lib/rails/commands/commands_tasks.rb:78:in `console' from /Users/gnerkus/.rvm/gems/ ruby-2.2.3@rails-experiments /gems/railties-5.0.0.beta1.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!' from /Users/gnerkus/.rvm/gems/ ruby-2.2.3@rails-experiments /gems/railties-5.0.0.beta1.1/lib/rails/command.rb:20:in `run' from /Users/gnerkus/.rvm/gems/ ruby-2.2.3@rails-experiments /gems/railties-5.0.0.beta1.1/lib/rails/commands.rb:19:in `<top (required)>' from bin/rails:4:in `require' from bin/rails:4:in `<main>' 

I traced the error of this block in the railtie.rb file in the Rails lib:

 def each_registered_block(type, &block) klass = self.class while klass.respond_to?(type) # The ':console' type doesn't seem to exist klass.public_send(type).each(&block) klass = klass.superclass end end 

which, in turn, comes from this block:

 def run_console_blocks(app) #:nodoc: each_registered_block(:console) { |block| block.call(app) } end 

I removed the spring gem and installed the rubocop . Otherwise, my Gemfile contains gems by default.

My version of Ruby 2.2.3 is higher than version 2.2.2 recommended for Rails 5.

Ruby version: 2.2.3p173 Rails version: 5.0.0.beta1.1 RVM version: 1.26.11

+5
source share
3 answers

The error was caused by the web-console stone, as indicated here: Error starting rails console . web-console was in version 3.1.0 at the time it was reported. Version 3.0.0 web-console did not seem to produce any errors while running the rails console .

You need to make sure that your version of web-console is 3.1.1 and higher, since the problem has been fixed in version 3.1.1 .

+5
source

gem install spring worked for me.

My problem:

 /usr/local/bin/NMONMerge.rb:209:in `block in <main>': undefined method `each' for nil:NilClass (NoMethodError) from /usr/local/bin/NMONMerge.rb:191:in `each' from /usr/local/bin/NMONMerge.rb:191:in `<main>' 
0
source

You need to install spring gem

 gem install spring --pre 
-2
source

Source: https://habr.com/ru/post/1241676/


All Articles