此Rails控制台错误消息有问题吗?

时间:2016-10-07 06:44:14

标签: ruby-on-rails console

对Rails来说很新,所以忍受我 -

目前偏执地认为我的ruby和gem版本不是最新的,因为我在运行rails test时偶尔会收到错误消息。之前已经安装了rvm和rbenv,但哇我已经删除了两个并重新安装了rvm。

当我进入irb并调用无效的操作时,例如:"foo".select,我收到一条简单的错误消息:

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

但是,当我在"foo".select中输入相同的命令rails console时,我得到:

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

这是正常的吗?或者这里的宝石出了什么问题?

1 个答案:

答案 0 :(得分:2)

你的宝石没什么问题。问题在于,当你运行irb时,就是这样。你只运行ruby interactive。 当您运行rails console以向您显示控制台时,需要使用ActiveRecord,rails core等为您设置它。所以这(下面)就是在它设置之前所做的全部。< / p>

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

请注意,irb的执行速度非常快,而rails console需要时间,具体取决于您的初始化程序,配置等。