Rails 3 - (incompatible character encodings: UTF-8 and ASCII-8BIT):

前端 未结 3 1858
滥情空心
滥情空心 2021-01-06 04:16

incompatible character encodings: UTF-8 and ASCII-8BIT

I\'m finding lots of old information yet scant advice about this error message but wondered w

3条回答
  •  轮回少年
    2021-01-06 04:40

    I've gotten this error when there is an encoding mismatch between how my Ruby app is parsing strings and how the database stores them.

    To fix this for myself when I'm dealing with UTF-8, I make sure I have this at the top of the .rb file in question:

    # encoding: utf-8
    

    Alternatively, you can globally set default UTF-8 encoding in your application config file with this line:

    Encoding.default_internal, Encoding.default_external = ['utf-8'] * 2
    

    And finally, I make sure that my database is using UTF-8 internally by setting the encoding option in database.yml:

    development:
      adapter: postgresql
      encoding: UTF8
      database: pg_development
      username: abe
      pool: 5
    

提交回复
热议问题