Rails fixtures encoding error "incompatible character encodings: ASCII-8BIT and UTF-8"
Using ruby 1.9.2 and Rails 3 I get an encoding error when I try to run this in seeds.rb
:
Fixtures.create_fixtures("#{Rails.root}/db/seed", "countries")
I am sure the .csv file is encoded in UTF-8 and it can be read and parsed using ruby's CSV class. Is this a Rails 3 encodin开发者_如何学JAVAg issue with fixtures?
I think the problem is in arel. I got the same thing when inserting a string with UTF-8 characters.
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'
Got around it thusly:
converter = Iconv.new 'UTF-8//IGNORE', 'UTF-8'
value = converter.iconv(value)
Don't think it will help much with your fixture problem, though...
精彩评论