How to view the entire Rails console history?
Ruby on-RailsRuby on-Rails Problem Overview
Does anyone know how to view the "history" in the rails console?
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 history
utility.
Is this possible in rails? If so, how?
Ruby on-Rails Solutions
Solution 1 - Ruby on-Rails
Look at ~/.irb-history
, you will find the history there.
Solution 2 - Ruby on-Rails
The best equivalent to the history
command would be
puts Readline::HISTORY.to_a
inside the IRB session. This has the advantage that no filesystem logging to any of the$HOME/.*_history
files needs to be configured (as is the case in AWS elastic beanstalk instances).
Solution 3 - Ruby on-Rails
I've tried the accepted answer, but our server didn't have a ~/.irb-history
.
As it turned out, the history was kept in ~/.pry_history
. Hope this helps.
Solution 4 - Ruby on-Rails
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
Solution 5 - Ruby on-Rails
Try CTRL+R
to open the search in the history
Solution 6 - Ruby on-Rails
We can view it by using following command in console
cat ~/.irb-history