Rails 3, heroku - PGError: ERROR: invalid byte sequence for UTF8 encoding:

I just accidentally got this strange error through Rails 3 on heroku (postgres)

PGError: ERROR: invalid byte sequence for encoding "UTF8": 0x85 HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding". : INSERT INTO "comments" ("content") VALUES ('BTW∑I re-listened to the video' ......

The hint, while pleasant, does nothing for me. Can I set the encoding somewhere? Should I even fight this? Has anyone seen this and / or had any ideas on how to deal with this type of problem?

thank

+5
source share
2 answers

, , , , PostgrSQL, UTF-8. , Rails UTF-8 .

( , ):

  • -, , config.encoding "utf-8" config/application.rb.

  • Ruby 1.9, toutf8.

  • , , SET CLIENT_ENCODING TO 'ISO-8859-1'; ( , ) PostgeSQL, . RESET CLIENT_ENCODING; reset .

  • Ruby 1.8 ( ), iconv UTF-8. . .

  • - (.. content content=) Base64. :

 

require 'base64'

class Comment
  def content
    Base64::decode64(self[:content])
  end

  def content=(value)
    self[:content] = Base64::encode64(value)
  end
end
+6

All Articles