Ruby on Rails - 固定装置使用错误的 utf-8 编码填充 sqlite3 数据库
使用 Fixtures 为 sqlite3 数据库播种确实适用于 config1,但使用 config2 utf-8 支持失败。
配置1:Ubuntu 11.04,ruby 1.9.2p136,Rails 3.0.3,“开发”环境
配置2:OS X Lion,ruby 1.9.2p290,Rails 3.0.3,“开发”环境
当有一个像我这样的yml文件时
001:
id: 1
name: "\xC3\xBC"
用它来填充数据库
Fixtures.create_fixtures(...)
在seed.rb中
然后数据库喊出有一个ID为1且名称为“ü”的条目。那是正确的。 这与 config1 一起工作。在 config2 中,我总是有一个名为“μ”的条目。 utf-8编码似乎失败了。
我已经在 Rails 项目中的所有位置打开了 UTF-8:
encoding: utf-8
在 database.yml 中
# encoding: utf-8
、在 seeds.rb 中
Encoding.default_external = "UTF-8"
Encoding.default_internal = "UTF-8"
config.encoding = "utf-8"
、在 config/environments/development.rb 中
Seeding the sqlite3 database with Fixtures did work with config1 but with config2 utf-8 support fails.
config1: Ubuntu 11.04, ruby 1.9.2p136, Rails 3.0.3, "development" environment
config2: OS X Lion, ruby 1.9.2p290, Rails 3.0.3, "development" environment
When having a yml file like
001:
id: 1
name: "\xC3\xBC"
I use it to populate the database with
Fixtures.create_fixtures(...)
in seed.rb
Afterwards the database shout have an entry with id 1 and name "ü". That would be correct.
That worked with config1. With config2 I alway have an entry with name "ü". utf-8 encoding seems to fail.
I already turned on UTF-8 everywhere in the rails project:
encoding: utf-8
in database.yml
# encoding: utf-8
in seeds.rb
Encoding.default_external = "UTF-8"
Encoding.default_internal = "UTF-8"
config.encoding = "utf-8"
in config/environments/development.rb
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这两个系统有可能具有不同的字节序吗?
来自 SQLite3 发行说明:
您可以在这里查看:
http://en.wikipedia.org/wiki/Endianness#Endianness_and_operating_systems_on_architectures
Is it possible that these two systems have different endianness?
From the SQLite3 release notes:
You can check here:
http://en.wikipedia.org/wiki/Endianness#Endianness_and_operating_systems_on_architectures