不兼容的字符编码:UTF-8 和 ASCII-8BIT SQL 服务器
incompatible character encodings: UTF-8 and ASCII-8BIT SQL Server
我的环境:Rails 4.2.4 Ruby 2.0 & SQL Server 2014,数据库级别的排序规则为 SQL_Latin1_General_CP1_CI_AS
。
我收到一个错误
incompatible character encodings: UTF-8 and ASCII-8BIT
当视图在数据库中发现某些特殊字符,如 ç、á、é 等时
我已经尝试了一些我读过的配置,但没有任何效果。
我在视图中试过这个:
# encoding: utf-8
在enviroment.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>
它工作正常,但这种方式非常困难。我想要在所有项目中 运行 的东西,例如模型
我试过角色class:
self.column.force_encoding("ISO-8859-1").encode("UTF-8")
但无法识别命令
有人可以帮我吗?
坦克!
麦酒
我的问题终于解决了。
一位同事给了我安装
的提示
tiny_tds
gem 和 运行 没有上面列出的任何设置,只需设置 database.yml
development:
adapter: sqlserver
mode: dblib
database: MyDataBase
dataserver: MyServer
之前我使用的是 ruby-odbc gem
谢谢!
我的环境:Rails 4.2.4 Ruby 2.0 & SQL Server 2014,数据库级别的排序规则为 SQL_Latin1_General_CP1_CI_AS
。
我收到一个错误
incompatible character encodings: UTF-8 and ASCII-8BIT
当视图在数据库中发现某些特殊字符,如 ç、á、é 等时
我已经尝试了一些我读过的配置,但没有任何效果。
我在视图中试过这个:
# encoding: utf-8
在enviroment.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>
它工作正常,但这种方式非常困难。我想要在所有项目中 运行 的东西,例如模型
我试过角色class:
self.column.force_encoding("ISO-8859-1").encode("UTF-8")
但无法识别命令
有人可以帮我吗?
坦克!
麦酒
我的问题终于解决了。 一位同事给了我安装
的提示tiny_tds
gem 和 运行 没有上面列出的任何设置,只需设置 database.yml
development:
adapter: sqlserver
mode: dblib
database: MyDataBase
dataserver: MyServer
之前我使用的是 ruby-odbc gem
谢谢!