我通过rvm在debian系统上使用rails 3.1.1和ruby-1.9.2-p290。 我在我的视图和mysql数据库中使用瑞典字母。 我一直在
不兼容的字符编码:UTF-8和ASCII-8BIT
当我访问一个从db获取内容的页面时。
在我的database.yml中我有这个:
staging:
adapter: mysql
database:something
encoding: utf8
username: something
password: something
host: localhost
production:
adapter: mysql
database:something
encoding: utf8
username: something
password: something
host: localhost
my config.ru:
Encoding.default_external = "UTF-8"
require ::File.expand_path('../config/environment', __FILE__)
run Someappname::Application
my environment.rb:
# Load the rails application
require File.expand_path('../application', __FILE__)
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
Someappname::Application.initialize!
我的config / initializers / encoding.rb:
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
我尝试过使用“Encoding.default_xxxxxx = Encoding :: UTF_8”的所有组合而没有它们
每个控制器,助手和邮件程序都以:
开头#encoding:UTF-8
在mysql中:
的MySQL>显示'char%'等变量;
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
输出来自:
的MySQL>显示'colla%'等变量;
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | latin1_swedish_ci |
| collation_database | utf8_general_ci |
| collation_server | latin1_swedish_ci |
知道我能做什么吗?我已经厌倦了这个问题!
答案 0 :(得分:4)
希望这可以帮助有同样问题的人!