Ruby-on-rails 如何查看整个 Rails 控制台历史记录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11601303/
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
How to view the entire Rails console history?
提问by dB'
Does anyone know how to view the "history" in the rails console?
有谁知道如何在 rails 控制台中查看“历史”?
Pressing the up arrow lets me iterate through recent commands, but I'd like to see them all together in a list. I'm basically looking for the rails equivalent of the Unix historyutility.
按向上箭头可让我遍历最近的命令,但我希望将它们全部放在一个列表中。我基本上是在寻找与 Unixhistory实用程序等效的 rails 。
Is this possible in rails? If so, how?
这在导轨中可能吗?如果是这样,如何?
回答by lucas clemente
Look at ~/.irb-history, you will find the history there.
看~/.irb-history,你会在那里找到历史。
回答by Perseids
The best equivalent to the historycommand would be
与history命令的最佳等价物是
puts Readline::HISTORY.to_a
inside the IRB session. This has the advantage that no filesystem logging to any of the$HOME/.*_historyfiles needs to be configured (as is the case in AWS elastic beanstalk instances).
在 IRB 会议中。这样做的优点是无需$HOME/.*_history配置任何文件的文件系统日志记录(就像 AWS 弹性 beantalk 实例中的情况)。
回答by Ja?ck
I've tried the accepted answer, but our server didn't have a ~/.irb-history.
我已经尝试了接受的答案,但我们的服务器没有~/.irb-history.
As it turned out, the history was kept in ~/.pry_history. Hope this helps.
事实证明,历史被保存在~/.pry_history. 希望这可以帮助。
回答by valk
Since we're already in the console,
由于我们已经在控制台中,
lines = File.read("#{ENV['HOME']}/.pry_history");
or
或者
lines = File.read("#{ENV['HOME']}/.irb-history");
then,
然后,
puts lines

