rails服务器可以工作,但是" rails console"不工作

时间:2016-02-05 00:40:14

标签: ruby-on-rails

我正在开发一个rails项目。使用命令"捆绑exec rails s"然而,我可以启动一个本地服务器,"捆绑exec rails c"抛出以下错误:

 /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler/setup (LoadError)
    from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/commands.rb:33:in `<module:Spring>'
    from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/commands.rb:4:in `<top (required)>'
    from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:77:in `preload'
    from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:143:in `serve'
    from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:131:in `block in run'
    from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:125:in `loop'
    from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:125:in `run'
    from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application/boot.rb:18:in `<top (required)>'
    from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'
  • Ruby版本:2.2.2
  • Rails版本:4.2.5
  • gem version:2.5.2
  • Bundler版本:1.11.2

[更新]:事​​实证明,评论&#34; spring&#34;在Gemfile中将解决这个问题。

3 个答案:

答案 0 :(得分:0)

你试过gem update --system吗?您可能需要更新版本的rubygems。

答案 1 :(得分:0)

如果您使用rvm使用以下设置默认的ruby版本,那么它将拾取正确的ruby版本。你可能需要在设置默认值

后运行bundle install / gem install rails -v 4.2.5
rvm --default 2.2.2

答案 2 :(得分:0)

好的,我在遇到与海报相同的问题后遇到了这个问题。他的更新建议从Gemfile中删除spring帮助我走上了正确的轨道。对我来说,问题是我引入了一个新的环境变量,但spring并没有采用。当您从Gemfile中删除spring时,它会阻止您的应用使用spring进程,但并没有真正停止spring进程,因此将其重新添加,进行捆绑安装或其他操作仍然会给您带来麻烦。春季进程正在运行。

要查看这是否可能是您的问题,可以检查bin/spring status并查看spring是否在后台运行以及是否已经运行了一段时间。

解决方案(至少对我来说):重新启动spring

bin/spring stop
rails c