How to view the entire Rails console history?

Ruby on-Rails

Ruby 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondB'View Question on Stackoverflow
Solution 1 - Ruby on-Railslucas clementeView Answer on Stackoverflow
Solution 2 - Ruby on-RailsPerseidsView Answer on Stackoverflow
Solution 3 - Ruby on-RailsJa͢ckView Answer on Stackoverflow
Solution 4 - Ruby on-RailsvalkView Answer on Stackoverflow
Solution 5 - Ruby on-RailsOfer ShapiraView Answer on Stackoverflow
Solution 6 - Ruby on-RailsJigar BhattView Answer on Stackoverflow