0

I ran ruby -e 'p Encoding.default_external and got this response.

<Encoding:CP850>

How do I change it to UTF-8?

desbest
  • 4,746
  • 11
  • 51
  • 84
  • what version of Ruby are you running? `UTF-8 is` the `default` encoding since Ruby 2. – K M Rakibul Islam Aug 12 '15 at 18:29
  • (Really, this is fairly searchable on the web, although Google is pretty good at knowing what I mean.) – Dave Newton Aug 12 '15 at 18:29
  • Here's [a link](http://stackoverflow.com/questions/20521371/set-utf-8-as-default-for-ruby-1-9-3) to a question asked similar to yours, answered. – Zader Aug 12 '15 at 18:32
  • `ruby -h` will give you the answer. – cremno Aug 12 '15 at 18:33
  • I'm using ruby 1.9.3. I searched google for `change ruby encoding` and didn't get any relevant results. – desbest Aug 12 '15 at 18:36
  • 1
    This seems to answer : http://stackoverflow.com/questions/20521371/set-utf-8-as-default-for-ruby-1-9-3 – Wand Maker Aug 12 '15 at 18:40
  • None of the links you have given me work. When I try to insert `£` into my database or display the `£` symbol in an xhtml file, I get an exception that a UTF-8 character cannot be displayed on a page with CP-850 encoding. This question will explain further. http://stackoverflow.com/questions/31909569/i-receive-incompatible-character-encodings-cp850-and-utf-8-when-displaying-th I have put `# encoding: UTF-8` `Encoding.default_external = 'utf-8'; Encoding.default_internal = Encoding::UTF_8` in my ruby file and it hasn't solved the problem. – desbest Aug 12 '15 at 18:46
  • @desbest You said the magic word, "database". Your database will have its own encoding, usually per table. – Schwern Aug 12 '15 at 19:05
  • The default I/O encoding is taken from your operating system's encoding settings. How to configure your operating system is a general user question, completely unrelated to programming, thus I vote to close as off-topic. (I would vote to migrate to SuperUser, except I'm betting this has already been asked there. Plus, the question doesn't have enough information, like what operating system the OP is using.) – Jörg W Mittag Aug 12 '15 at 19:06
  • This is not a database question @Schwern as I get an exception when I display a web page that has the `£` character on it. Also @Jörg I get the same error on Heroku, so it happens on both Windows and Linux. – desbest Aug 12 '15 at 19:12
  • This answer looks promising. How do I make it work? http://stackoverflow.com/a/17616076/337306 – desbest Aug 12 '15 at 19:27
  • I can't use this answer as I don't have the LC_ALL environment variable. http://stackoverflow.com/a/17616076/337306 – desbest Aug 14 '15 at 10:30

0 Answers0