ruby `encode': “\xC3” from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)

后端 未结 4 1409
执念已碎
执念已碎 2020-12-05 22:45

Hannibal episodes in tvdb have weird characters in them.

For example:

Œuf

So ruby spits out:

./manifesto.rb:19:in `         


        
4条回答
  •  萌比男神i
    2020-12-05 23:37

    I just suffered through a number of hours trying to fix a similar problem. I'd checked my locales, database encoding, everything I could think of and was still getting ASCII-8BIT encoded data from the database.

    Well, it turns out that if you store text in a binary field, it will automatically be returned as ASCII-8BIT encoded text, which makes sense, however this can (obviously) cause problems in your application.

    It can be fixed by changing the column encoding back to :text in your migrations.

提交回复
热议问题