command history in Rails console over PuTTY

对着背影说爱祢 提交于 2019-12-11 05:52:29

问题


Using script/console in rails 2.3.12 over PuTTY. When I press the "up" arrow to access the last command I wrote, instead of bringing up the command it just prints the weird string "^[[A" to the terminal. Same with other arrows...back arrow prints "^[[D" and forward arrow prints "^[[C"

Hoping somebody recognizes these weird codes, and can possibly tell me how to get the arrows working properly. Is this a PuTTY settings issue?


回答1:


The up-arrow functionality is supplied by readline. Typically, when ruby is built, ./configure auto-detects the readline libraries and builds ruby mappings to them. Sometimes this doesn't work and you have to install new libraries or custom configure --with-readline-dir when building ruby. irb and rails-console just use the readline capability of the ruby stdlib, soyour problem is likely that your ruby build didn't detect and bind readline.

I suggest you survey the other SO questions relevant to building ruby with readline to see if one of them gives you guidance for your version of ruby and your OS.




回答2:


I used this, and it worked for me with JRuby 1.6.7 and Rails 2.3.8 (see link for original solution)

It looks like bundler prevents the irb console from using readline. You can work around this by putting the following line in your .irbrc, which will force irb to use readline:

IRB.conf[:USE_READLINE] = true

as suggested here

Running rails console with bundle exec

hope this helps.



来源:https://stackoverflow.com/questions/9760564/command-history-in-rails-console-over-putty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!