我正在使用 Amazon RDS 作为数据库在 Heroku 上设置 Rails(2.3.5) 应用程序的新实例。我想对所有东西都使用 UTF-8。由于默认情况下 RDS 不是 UTF-8,因此我设置了一个新的参数组并将数据库切换为使用该参数组,基本上按照this。似乎奏效了:
SHOW VARIABLES LIKE '%character%';
character_set_client utf8
character_set_connection utf8
character_set_database utf8
character_set_filesystem binary
character_set_results utf8
character_set_server utf8
character_set_system utf8
character_sets_dir /rdsdbbin/mysql-5.1.50.R3/share/mysql/charsets/
此外,我已成功设置 Heroku 以使用 RDS 数据库。在 rake db:migrate 之后,一切看起来都很好:
CREATE TABLE `comments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`commentable_id` int(11) DEFAULT NULL,
`parent_id` int(11) DEFAULT NULL,
`content` text COLLATE utf8_unicode_ci,
`child_count` int(11) DEFAULT '0',
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `commentable_id` (`commentable_id`),
KEY `index_comments_on_community_id` (`community_id`),
KEY `parent_id` (`parent_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
在标记中,我包括:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
另外,我设置了:
production:
encoding: utf8
collation: utf8_general_ci
...在 database.yml 中,尽管我不太相信在这种情况下是否会采取任何措施来尊重这些设置,因为 Heroku 在连接到 RDS 时似乎正在做自己的配置。
现在,我通过应用程序中的表格输入评论:“Úbe® ƒåiL”,但在数据库中我有“Úbe® Æ'Ã¥iL”
当 Rails 将它从数据库中加载回并呈现到页面时,它看起来很好,所以无论它以一种方式做什么,它都会以另一种方式撤消。如果我查看 Sequel Pro 中的 RDS 数据库,如果我将编码设置为“UTF-8 Unicode via Latin 1”看起来不错。因此,Latin-1 似乎在某个地方潜入了那里。
当连接到本地 MySQL 数据库时,一切都在开发中工作。
以前一定有人这样做过,对吧?我错过了什么?