【问题标题】:incompatible character encodings: UTF-8 and ASCII-8BIT SQL Server不兼容的字符编码:UTF-8 和 ASCII-8BIT SQL Server
【发布时间】:2016-04-27 20:09:02
【问题描述】:

我的环境:Rails 4.2.4 Ruby 2.0 和 SQL Server 2014,数据库级别的排序规则为 SQL_Latin1_General_CP1_CI_AS

我遇到了一个错误

不兼容的字符编码:UTF-8 和 ASCII-8BIT

当视图在数据库中发现一些特殊字符,如ç、á、é等时。

我已经尝试了一些我阅读的配置,但没有任何效果。

我在视图中试过这个:

# encoding: utf-8

在 environment.erb 中:

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

在application.rb中:

config.encoding = "utf-8"

我在视图中试过:

<td><%=h role.description.force_encoding("ISO-8859-1").encode("UTF-8") %></td>

它工作正常,但这种方式非常困难。我想要在所有项目中运行的东西,例如在模型上运行

我尝试过角色类:

   self.column.force_encoding("ISO-8859-1").encode("UTF-8")

但无法识别命令

有人可以帮帮我吗?

坦克!

麦芽酒

【问题讨论】:

    标签: utf-8 sql-server-2014


    【解决方案1】:

    我终于解决了我的问题。 一位同事给了我安装

    的提示

    tiny_tds

    gem 并在没有上面列出的任何设置的情况下正常运行,只需设置 database.yml

    development:
        adapter: sqlserver
        mode: dblib
        database: MyDataBase
        dataserver: MyServer
    

    以前我使用的是 ruby​​-odbc gem

    谢谢!

    【讨论】:

      猜你喜欢
      • 2011-07-14
      • 1970-01-01
      • 1970-01-01
      • 2011-10-17
      • 2011-05-26
      • 2011-12-14
      • 2012-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多