呸!我在 ruby 1.9.2 的 Rails 中不断收到此编码错误
我通过 rvm 在 debian 系统上使用 Rails 3.1.1 和 ruby-1.9.2-p290。 我在视图和 mysql 数据库中使用瑞典字母。 我不断得到
不兼容的字符编码:UTF-8 和 ASCII-8BIT
当我访问从数据库获取内容的页面时,UTF-8 和 ASCII-8BIT。
在我的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
我的config.ru:
Encoding.default_external = "UTF-8"
require ::File.expand_path('../config/environment', __FILE__)
run Someappname::Application
我的环境.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”的所有组合,并且没有它们到
Every控制器、助手和邮件程序开头为:
#编码: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 |
知道我能做什么吗?我正打算对这个问题感到非常厌倦!
I use rails 3.1.1 with ruby-1.9.2-p290 on a debian system through rvm.
I use swedish letters in my views and in the mysql database.
I keep getting
incompatible character encodings: UTF-8 and ASCII-8BIT
when I visit a page that get's stuff from the db.
in my database.yml i have this:
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!
my config/initializers/encoding.rb:
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
I have tried with all combinations of "Encoding.default_xxxxxx = Encoding::UTF_8" and without them to
Every controller, helper and mailer starts with:
# encoding: UTF-8
In mysql :
mysql> show variables like '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/ |
+--------------------------+----------------------------+
And the output from:
mysql> show variables like 'colla%';
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | latin1_swedish_ci |
| collation_database | utf8_general_ci |
| collation_server | latin1_swedish_ci |
Any idea of what I can do? I'm strating to get really tired of this problem!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,看来我成功解决了这个问题!
问题是我同时使用mysql和mysql2。
所以为了解决这个问题,我必须删除mysql并获取mysql2“0.3.7”,否则devise会向我抛出奇怪的错误。
然后我不得不将database.yml中的适配器更改为适配器:mysql2
希望这可以帮助遇到同样问题的人!
Okey, seems that I managed to solve the problem!
The problem was that I was using mysql and mysql2 at the same time.
So to solve it, I had to delete mysql and grab the mysql2 "0.3.7" or else devise was throwing strange errors at me.
And then I had to change the adapter in database.yml to adapter: mysql2
Hope this helps someone having the same problem!