在我的Rails应用程序的根目录中运行rails console
的任何尝试都会产生以下错误:
未定义的方法`每个' for 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>'
我已在Rails lib的railtie.rb
文件中跟踪此块的错误:
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
我卸载了spring
gem并安装了rubocop
gem。否则,我的Gemfile
包含默认宝石。
我的Ruby版本为2.2.3
,高于推荐用于Rails 5的2.2.2
版本。
Ruby版本: 2.2.3p173
Rails版本: 5.0.0.beta1.1
RVM版本: 1.26.11
答案 0 :(得分:5)
错误是由此处引用的web-console
gem引起的:Error when running rails console。报告此时web-console
版本为3.1.0
。执行3.0.0
时,web-console
版rails console
似乎没有产生任何错误。
您需要确保web-console
版本3.1.1
更高,因为问题已在3.1.1
版本中修复。
答案 1 :(得分: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>'
答案 2 :(得分:-2)
您需要安装spring gem
gem install spring --pre