Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get the Ruby on Rails console to remember my command history, umm, better?

I'm using the console in Ruby on Rails 3.1.1, and I'm finding its command history (up arrow) to be really flaky. I've run the commands p = Product.by_name 'Acme' and p.add_search_term('Snipe') several times today, across several console sessions.

Yet, when I reload the Ruby on Rails console, only the first one shows in my command history, not the second. Sometimes they are both there in the history after I reload the console. On top of that, I see commands in my history that are from several days ago after pressing up arrow only a few times. Is there some sort of configuration that I need to change or is this a bug?

  • Ruby on Rails 3.1.1`
  • Ruby 1.9.2p290`
  • Ubuntu 11.10`
like image 246
jcollum Avatar asked May 05 '12 19:05

jcollum


People also ask

Where is IRB history stored?

IRB or rails console commands are stored in the file irb-history. If you are using pry. You can find your history in ~/. pry_history file.

What is Rails console?

Rails console is an irb session that is built into the rails environment and is accessed by typing rails c into the terminal. It can be used to test association methods, validations and check error messages when building a rails app.

How to Start a Rails console?

Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias "s" to start the server: bin/rails s . The server can be run on a different port using the -p option. The default development environment can be changed using -e .


1 Answers

From How To – Persist Rails or IRB Console Command History After Exit.

Create, or edit your ~/.irbrc file to include:

require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 200
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-history"
like image 124
ctcherry Avatar answered Oct 02 '22 07:10

ctcherry