Rails灯具编码错误“不兼容的字符编码:ASCII-8BIT和UTF-8”

时间:2010-09-16 18:39:05

标签: ruby-on-rails utf-8 character-encoding

使用ruby 1.9.2和Rails 3当我尝试在seeds.rb中运行时出现编码错误:

Fixtures.create_fixtures("#{Rails.root}/db/seed", "countries")

我确信.csv文件是用UTF-8编码的,可以使用ruby的CSV类读取和解析.csv文件。这是固定装置的Rails 3编码问题吗?

1 个答案:

答案 0 :(得分:1)

我认为问题出在了问题上。插入带有UTF-8字符的字符串时,我得到了同样的东西。

 arel (2.0.4) lib/arel/visitors/to_sql.rb:70:in `join'
 arel (2.0.4) lib/arel/visitors/to_sql.rb:70:in `visit_Arel_Nodes_Values'
 arel (2.0.4) lib/arel/visitors/visitor.rb:15:in `visit'
 arel (2.0.4) lib/arel/visitors/to_sql.rb:60:in `visit_Arel_Nodes_InsertStatement'
 arel (2.0.4) lib/arel/visitors/visitor.rb:15:in `visit'
 arel (2.0.4) lib/arel/visitors/visitor.rb:5:in `accept'
 arel (2.0.4) lib/arel/visitors/to_sql.rb:19:in `block in accept'
 activerecord (3.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:110:in `with_connection'
 arel (2.0.4) lib/arel/visitors/to_sql.rb:17:in `accept'
 arel (2.0.4) lib/arel/tree_manager.rb:19:in `to_sql'
 arel (2.0.4) lib/arel/select_manager.rb:191:in `insert'

如此:

converter = Iconv.new 'UTF-8//IGNORE', 'UTF-8'
    value = converter.iconv(value)

不要认为它对你的灯具问题有多大帮助,不过......