Very strange: Umlauts (äöü) aren't displayed correctly in

Hi all

Take a look at the following video, please… I just’ can’t help me
anymore…

http://josh.ch/files/temp/rails_problem.mov

I’m sorry for the bad quality, it’s just a demo of Snapz Pro X 2… :wink:
But I hope you’ll see enought…

Thanks for any help.
Josh

Hi,

I think the problem is in Firefox, that the UTF-8 declaration is
missing in the header.

Try it :slight_smile:

Beate

Hi,

That’s a nice movie, but really, have you checked what headers are sent
to the browser? Can you something similar to

wget --save-headers http://youhost/path/to/your/app

and see if there’s charset there.

If it’s not there try adding the following to ApplicationController:

after_filter :set_charset

def set_charset
content_type = @headers[“Content-Type”] || ‘text/html’
if /^text//.match(content_type)
@headers[“Content-Type”] = “#{content_type}; charset=utf-8”
end
end

If anyone has a nicer solution please let me know.

Best regards,
Yuri

wget --save-headers http://youhost/path/to/your/app

There really was no charset…

If it’s not there try adding the following to ApplicationController:

after_filter :set_charset

def set_charset
content_type = @headers[“Content-Type”] || ‘text/html’
if /^text//.match(content_type)
@headers[“Content-Type”] = “#{content_type}; charset=utf-8”
end
end

Now the headers do have a charset:

Host: localhost:3007
User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US;
rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7
Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,/;q=0.5
Accept-Language: en-us,en-gb;q=0.7,de-ch;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: _session_id=68e4e78cad839de4bea6b26894cae57c
Cache-Control: max-age=0

But it’s still full of “???” for “äöü”. Absolutely frustrating… :frowning:

and (funny stuff): safari now also only shows questionmarks…
The problem must be somewhere else… banging-my-head-on-the-keyboard

You are using RJS?

Check youre headers for this.
I am having the same problem.

But for me it works in Firefox but not in Safari.

Peter wrote:

You are using RJS?
Why do you think that?

Check youre headers for this.
I am having the same problem.

But for me it works in Firefox but not in Safari.

Very, very strange and extremely frustrating… My apps all act a little
different. Either they display the stuff correctly in the Rails app but
e.g. not in phpMyAdmin/CocoaMySQL or vice versa… :frowning:

Thanks a lot for your help, I’m gonna try that.

But why isn’t there just a switch in Rails that allows me poor german
(swiss german) user to use my beloved umlauts? What about convention
over configuration? In this way Rails is still very unfriendly (also in
things like the auto-generated form validation errors… try to use them
in a german app!)…

Joshua,

There’s a lot you need to do to make Rails handle UTF8 correctly. See
http://wiki.rubyonrails.com/rails/pages/HowToUseUnicodeStrings

In short:

  1. You need to make sure your database is set to use UTF8, which it
    probably won’t be if you’ve created it in CocoaMySQL. Use ALTER
    DATABASE xyz CHARSET=‘utf8’

  2. You need to tell Rails to speak to the database in UTF8 by adding
    “encoding: utf8” to each database in database.yml

  3. You need to tell Ruby that you want to use UTF8 by putting the
    following in your environment.rb:
    require ‘jcode’
    $KCODE=‘u’

  4. You need to make Rails pass back the correct content type header
    by putting the following in application.rb:
    after_filter :set_charset

    def set_charset
    content_type = @headers[“Content-Type”] || ‘text/html’
    if /^text//.match(content_type)
    @headers[“Content-Type”] = “#{content_type}; charset=utf-8”
    end
    end

Cheers,

Pete Y.

Joshua M. wrote:

But why isn’t there just a switch in Rails that allows me poor german
(swiss german) user to use my beloved umlauts?

The simple answer is that nobody has built it yet! There are now a
couple of plugins floating around that provide much better unicode
handling, and there’s discussion going on about including some of this
in Rails 1.2. You can expect the situation to improve with time.

Cheers,

Pete Y.