6

任何尝试rails console在我的 Rails 应用程序的根目录中运行都会产生以下错误:

nil:NilClass (NoMethodError) 的未定义方法“每个”

完整的堆栈跟踪:

 /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>'

railtie.rb我已经在 Rails 库中的文件中将错误追溯到此块:

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

这又来自这个块:

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

我卸载了springgem 并安装了rubocopgem。否则,我的Gemfile包含默认宝石。

我的 Ruby 版本2.2.3高于2.2.2Rails 5 推荐的版本。

Ruby 版本: 2.2.3p173 Rails 版本: 5.0.0.beta1.1 RVM 版本: 1.26.11

4

3 回答 3

5

该错误是由web-console此处引用的 gem 引起的:运行 rails console 时出错web-console报告时的版本3.1.0。的3.0.0版本在执行web-console时似乎没有产生任何错误rails console

您需要确保您的web-consoleis3.1.1和更高版本,因为该问题已在3.1.1版本中修复。

于 2016-01-28T05:41:53.827 回答
0

gem install spring为我工作。

我的问题是:

/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>'
于 2016-04-26T12:29:50.430 回答
-2

你需要安装spring gem

gem install spring  --pre
于 2016-01-28T08:09:45.580 回答