How can I enter multibyte characters in the rails (or irb) console?

guys. I am developing a Chinese application with rails. Now I want to enter some Chinese characters in the rails console, but I can not do this, either in irb.

Any guys who have experience to solve this problem? I would be grateful for your help!

+7
source share
3 answers

I found a solution for me, it needs to recompile readline. And now I can enter non-ASCII characters!

Because I use rvm, so I found this article to teach you how to recompile readline under rvm. http://rvm.beginrescueend.com/packages/readline/

And for those who do not use rvm, perhaps you can follow this post and try: http://henrik.nyh.se/2008/03/irb-readline

By the way, ruby-1.9.2 irb already supports non-ASCII input.

+2
source

Based on @ Jimmy-Huang's answer, these are the steps I followed on a Mac Leopard using rvm and ruby ​​1.9.2:

rvm package install readline rvm remove 1.9.2 rvm install 1.9.2 --with-readline-dir=$rvm_path/usr 

This led to some errors, especially when trying to bundle install :

uninitialized constant Gem :: SilentUI

It turned out that due to an older version of bundler and this gets rid of it:

 gem install bundler 
+5
source

Check the package method in the array: http://ruby-doc.org/core-1.8.7/classes/Array.html#M000287

I think you need:

 [111 ,222, 333].pack(U*) 

Here is an interesting discussion on this issue with Matz:

http://www.ruby-forum.com/topic/134919

+1
source

All Articles