这个Rails控制台错误消息有什么问题吗?

时间:2021-01-04 18:10:43

Very new to Rails, so bear with me -

Rails很新,所以请容忍我

Currently paranoid that my ruby and gem versions aren't up to date because I'd occasionally get error messages when running rails test. Previously had rvm and rbenv both installed, but wow I've removed both and reinstalled rvm only.

目前,我非常担心我的ruby和gem版本没有更新,因为在运行rails测试时,我偶尔会收到错误消息。之前已经安装了rvm和rbenv,但是我只删除和重新安装了rvm。

When I go into a irb and call an action that doesn't work, such as: "foo".select, I get a simple error message:

当我进入一个irb,并调用一个不起作用的动作,比如:“foo”。选择,我得到一个简单的错误消息:

NoMethodError: private method 'select' called for "foo":String
    from (irb):4
    from /Users/Joseph/.rvm/rubies/ruby-2.3.1/bin/irb:11:in '<main>'

However, when I type the same command "foo".select in rails console instead, I get:

但是,当我输入相同的命令“foo”时。在rails控制台中选择,我得到:

NoMethodError: private method `select' called for "foo":String
    from (irb):1
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in `start'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/Joseph/workspace/sample_app/bin/rails:9:in `<top (required)>'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/commands/rails.rb:6:in `call'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/command_wrapper.rb:38:in `call'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:191:in `block in serve'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:161:in `fork'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:161:in `serve'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:131:in `block in run'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:125:in `loop'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:125:in `run'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /Users/Joseph/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/Joseph/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'

Is this normal? Or is there something wrong with my gems here?

这是正常的吗?还是我的宝石有问题?

1 个解决方案

#1


2  

There's nothing wrong with your gems. The thing is that when you run irb, it's just that. You only run the ruby interactive. When you run rails console in order to show you the console it needs to go and set it for you with ActiveRecord, rails core, etc. So this (below) is all it does before it's set.

你的宝石没有错。问题是,当你运行irb时,就是这样。您只运行ruby交互。当您运行rails控制台以显示控制台时,它需要使用ActiveRecord、rails core等为您设置控制台。

from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in `start'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/Joseph/workspace/sample_app/bin/rails:9:in `<top (required)>'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/commands/rails.rb:6:in `call'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/command_wrapper.rb:38:in `call'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:191:in `block in serve'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:161:in `fork'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:161:in `serve'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:131:in `block in run'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:125:in `loop'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:125:in `run'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /Users/Joseph/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/Joseph/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'

Notice that irb is executed really fast, while rails console takes its time, depending on your initializers, configurations, etc.

注意irb的执行速度非常快,而rails控制台则需要时间,这取决于初始化器、配置等等。

#1


2  

There's nothing wrong with your gems. The thing is that when you run irb, it's just that. You only run the ruby interactive. When you run rails console in order to show you the console it needs to go and set it for you with ActiveRecord, rails core, etc. So this (below) is all it does before it's set.

你的宝石没有错。问题是,当你运行irb时,就是这样。您只运行ruby交互。当您运行rails控制台以显示控制台时,它需要使用ActiveRecord、rails core等为您设置控制台。

from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in `start'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/Joseph/workspace/sample_app/bin/rails:9:in `<top (required)>'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/commands/rails.rb:6:in `call'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/command_wrapper.rb:38:in `call'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:191:in `block in serve'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:161:in `fork'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:161:in `serve'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:131:in `block in run'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:125:in `loop'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application.rb:125:in `run'
    from /Users/Joseph/.rvm/gems/ruby-2.3.1@sample_app/gems/spring-1.7.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /Users/Joseph/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/Joseph/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'

Notice that irb is executed really fast, while rails console takes its time, depending on your initializers, configurations, etc.

注意irb的执行速度非常快,而rails控制台则需要时间,这取决于初始化器、配置等等。