无论出于什么原因,rails console都拒绝启动,它只是挂起。我没有对我的代码进行任何更改,而使用相同版本的ruby和rails的其他项目也没有问题。当我最终按Ctrl + C时,我得到这个堆栈跟踪,指向spring。
我无法解释为什么这种情况从一个时刻发生到另一个时刻,它工作得很好。我通过RVM清除了所有的宝石,并通过捆绑命令重新安装,但仍然没有运气。任何想法,将不胜感激。
此外,rails服务器也没有问题,据我所知,问题与项目有关,但是没有代码发生变化,而且只有rails控制台存在问题。
Ruby 2.1.2 Rails 4.1.4
user_a@ubuntu:~/work/app_a$ rails console
^C/home/user_a/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/run.rb:54:in `gets': Interrupt
from /home/user_a/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/run.rb:54:in `verify_server_version'
from /home/user_a/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/run.rb:25:in `call'
from /home/user_a/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /home/user_a/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/rails.rb:23:in `call'
from /home/user_a/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /home/user_a/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
from /home/user_a/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
from /home/user_a/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
from /home/user_a/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
from /home/user_a/work/app_a/bin/spring:16:in `require'
from /home/user_a/work/app_a/bin/spring:16:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
user_a@ubuntu:~/work/app_a$
答案 0 :(得分:364)
重新启动弹簧应修复挂起命令:
$ bin/spring stop
删除并重新创建新的Rails应用程序后,我遇到了挂起命令(rake,bin / rails等)。谷歌并没有那么有用。我希望这是。
当您重新运行命令时,Spring将自动启动。
答案 1 :(得分:7)
我认为Spring gem版本有问题。
转到你的Gem文件并评论gem&#39; spring&#39;。然后运行bundle install并重试。
# gem 'spring'
然后:
bundle install
如果您的工作取决于宝石,请尝试通过以下方式更新宝石:
bundle update
答案 2 :(得分:1)
如果$ bin/spring stop
无法解决问题,请检查以确保没有孤立的Spring进程仍然存在:
$ ps aux | grep -i spring
如果您看到类似
的内容user 7163 0.0 0.0 110356 2165 pts/3 S+ 19:40 0:00 grep --color=auto -i spring
user 16980 0.0 0.4 398826 17580 ? Sl Aug31 0:00 spring server | current | started 277 hours ago
然后杀死错误的弹簧过程并尝试再次启动控制台:
$ kill -9 16980
$ rails c
答案 3 :(得分:0)
当怀疑春天是奇怪的原因时, 尝试运行此命令
spring stop && spring start
答案 4 :(得分:0)
在spring gem的lib / application.rb文件中更改以下方法(可以使用gem info spring命令显示路径)可以做到这一点:
def eager_preload
with_pty do
# we can't see stderr and there could be issues when it's overflown
# see https://github.com/rails/spring/issues/396
STDERR.reopen("/dev/null")
preload
end
end
请参阅https://github.com/markiz/spring/commit/5f3ab734fc45d541aaaccb05b59cd95aa49fe8ef