utf-8 or encoding problems, need help!

I am scratching my head here, but isn't there a way to have the form force a character encoding in the POST request?

i.e. you can explicitly state that the POST character data is utf-8?

THat way the user can mess around with their character encodings all they want, but whatever characters submitted will be valid utf-8 characters (but possibly/probably not the characters they expected).

That's what the accept-charset is for on the form element. However, if your page is by itself explicitly UTF-8 (via output headers or he <head> element, or both) all forms that you postback or get should be automagically in UTF-8 as well.

Hi, I'm having a related utf8-problem I would like to share in this topic.

When I'm submitting swedish characters (such as åäö) in a ajaxcall (:observe_field) the åäö-characters gets translated into weird characters that causes the postgresql to display the error: PGError: ERROR: invalid byte sequence for encoding "UTF8": 0xf6f6f6f6

Anyone know a fix? :slight_smile:

Hi, I'm having a related utf8-problem I would like to share in this topic.

When I'm submitting swedish characters (such as åäö) in a ajaxcall (:observe_field) the åäö-characters gets translated into weird characters that causes the postgresql to display the error: PGError: ERROR: invalid byte sequence for encoding "UTF8": 0xf6f6f6f6

Its pretty clear that you are inserting high bit latin-1 (?) characters into your UTF-8 database. (?) I am assuming that scandinavian countries are part of the latin-1 (ISO-8859-1) character set.

Anyone know a fix? :slight_smile:

Are you (1) typing these characters into your source file or are you (2) letting the user enter them directly from a form?

(1) I suspect you will need to escape the characters in your source file. I don't know enough about using non-ASCII characters in Ruby source to help you further

(2) should work as long as you just let Rails pass them through, and screen them for being valid utf-8. Make sure your browser knows the page is UTF-8 (you will need to do something in your Rails config to enforce this) and that any POSTs are encoding the data as UTF-8.

Hi, thanks for the reply. The answer is 2 : the user is entering the text. I don't understand why rails processes the characters correctly through normal posts, but not when I do the ajax obversefield-call.

Anyhow, how do I specify to use UTF-8 in that ajax-call?

My database is UTF-8.

This is what I have right now:

In applicationcontroller: before_filter :set_charset # Sets default character set to UTF-8 def set_charset   if request.xhr?     @headers["Content-Type"] = "text/javascript; charset=utf-8"   else     @headers["Content-Type"] = "text/html; charset=utf-8"   end end

At the bottom of environment.rb I have: $KCODE = 'u' require 'jcode'