Ruby-on-rails 出错后退出 Rails 控制台

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6259654/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 01:20:36  来源:igfitidea点击:

Exiting the Rails console after an error

ruby-on-rails

提问by EverTheLearner

I have been use the rails console for testing and learning purposes and when I encounter an error I cannot exit anymore using the "Control + C" command. Is there another command to exit? This is what the console looks like when I try to do this:

我一直在使用 rails 控制台进行测试和学习,当我遇到错误时,我无法再使用“Control + C”命令退出。是否有其他命令退出?这是我尝试执行此操作时控制台的样子:

ruby-1.9.2-p180 :026 > user.find_by_name("Test")
NoMethodError: undefined method `find_by_name' for #<User:0x00000100f991a0>
    from /Users/easierlife/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/activemodel-3.0.7/lib/active_model/attribute_methods.rb:367:in `method_missing'
    from /Users/easierlife/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/activerecord-3.0.7/lib/active_record/attribute_methods.rb:46:in `method_missing'
    from (irb):26
    from /Users/easierlife/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start'
    from /Users/easierlife/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start'
    from /Users/easierlife/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/railties-3.0.7/lib/rails/commands.rb:23:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
ruby-1.9.2-p180 :027 > ^C^C^C^C^C

Thanks

谢谢

回答by Zabba

You could try:

你可以试试:

  • CtrlD
  • CtrlZand then Enter
  • Typing exit, then Enter.
  • CtrlD
  • CtrlZ进而 Enter
  • 打字exit,然后Enter

回答by corroded

if the above fails, open another terminal then:

如果上述方法失败,请打开另一个终端,然后:

ps aux | grep ruby

you'll get something like:

你会得到类似的东西:

username      917  52.7  0.4  2455912  17484 s000  R+    9:22AM   0:01.13 /Users/yourusername/.rvm/rubies/ruby-1.9.2-p180/bin/ruby script/rails c

you'll need the "917" id:

你需要“917”ID:

sudo kill -9 917

(also i think this should be migrated to superuser.com)

(我也认为这应该迁移到 superuser.com)

回答by Akash Jain

You can come out from console screen by simply typing 'exit' on console and pressing 'enter'.

您只需在控制台上键入“exit”并按“enter”即可从控制台屏幕出来。

but today i faced some weird issue, when i displayed all records available in table which exceeds console screen size

但是今天我遇到了一些奇怪的问题,当我显示表格中超过控制台屏幕大小的所有可用记录时

then i pressed enterbutton until we reach end of records, now if we press "Control + C", "Control + Z" and exit commands nothing worked for me.

然后我按下回车按钮,直到我们到达记录的末尾,现在如果我们按下“Control + C”、“Control + Z”和退出命令,对我来说没有任何作用。

I get stuck on console screen and screen was not allowing me to do anything.

我卡在控制台屏幕上,屏幕不允许我做任何事情。

Finally got Solution!!!!

终于有解决方案了!!!!

press 'q' key 

BooM!!

繁荣!!

Now every thing normal :)

现在一切正常:)