呸!我在 ruby​​ 1.9.2 的 Rails 中不断收到此编码错误

发布于 2024-12-11 23:00:44 字数 2455 浏览 0 评论 0原文

我通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧伤还要旧人安 2024-12-18 23:00:44

好吧,看来我成功解决了这个问题!
问题是我同时使用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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文