Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

incompatible character encodings: UTF-8 and ASCII-8BIT for Rails 3

#3947

I'm running Rails with 1.9.2(trunk).

This might be a duplicate of #2188 Encoding error in Ruby1.9 for templates, but I didn't have any problem with rails 2.3.5.
So I get this on Rails 3:
"incompatible character encodings: UTF-8 and ASCII-8BIT" Then it shows me the line in the template.

I'm just retrieving a String from a sqlite3 database (this does not happen with I18n YAML files), and the String get tagged of ASCII-8BIT.

Adding str.force_encoding('utf-8') works but it's not really DRY neither convenient.
Changing default internal/external didn't work.

I'm using Haml, but it did fail the same way with Erb.

Why does this 'regression' happen ? I mean 2.3.5 did deal good with that.

Maybe be a config encoding option in application.rb might be interesting, or make everything utf-8 default.

PS: I get the same error on the form around this:
= f.label :date = f.datetime_select :date From when showing select for date have any special character not in ASCII-7BIT ? Looks really weird, because it's another field who's responsible of the encoding mismatch.

Reported by Benoit Daloze · February 13th, 2010 @ 10:46 AM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Balazs Nagy
    Balazs Nagy

    sqlite3-ruby is not yet upgraded to support ruby 1.9. There is, however, a ticket by sqlite3-ruby's developer to get some updates to ActiveRecord's sqlite3 interface some time now: #3790 SQLite3 driver is changing, please update accordingly

    I expect once this will be added to the recent versions of ActiveRecord, the new sqlite3 driver will follow soon with ruby 1.9 encoding support.

    February 13th, 2010 @ 08:15 PM

  2. Benoit Daloze
    Benoit Daloze

    Hi,

    I just tried with mysql, and got the same error.

    I tried also with git's version of tenderlove's sqlite3-ruby, but I didn't manage to make it work (LoadError: no such file to load -- sqlite3/sqlite3_native).

    mysql tagged, as sqlite3 the string as ASCII-8BUT, which is non-sense.

    Isn't it rails3's fault to tag these String like that?
    It doesn't look of a hazard both fail the same way ...

    Thanks for your answer

    February 14th, 2010 @ 12:32 AM

  3. Yaroslav Markin
    Yaroslav Markin

    MySQL driver is buggy as well; There is stuff like http://github.com/brianmario/mysql2, but, actually, this is not a Rails bug but a driver bug.

    Latest Postgres binary gem (gem install pg) recognizes UTF-8 just fine.

    April 10th, 2010 @ 07:49 PM

  4. Ryan Bigg
    Ryan Bigg
    • State changed from new to invalid

    Related ticket #3790 SQLite3 driver is changing, please update accordingly committed. This issue is no longer valid.

    April 11th, 2010 @ 10:58 PM

  5. Benoit Daloze
    Benoit Daloze

    Ok,

    Thanks for the answers.

    Regards,
    B.D.

    (I spoke of regression because rails 2.3.5 did worked with ruby 1.9 and these encodings)

    April 12th, 2010 @ 09:31 AM