Textarea problem with accentued chars


#1

Hello, I have a problem with accentued characters return from a textarea

I have 3 simple files to show example ( below ).

index.rhml : If I put “énial” inside the textarea, then submit to
:action => post

post.rhml : wrote

énial

195

“\303\251nial”

//

params[:comment][:message] return => énial

params[:comment][:message][1] return => 195 ! ( 195 is not “é” ,
http://www.asciitable.com/ )

params[:comment][:message].inspect return => “\303\251nial”

and in ddb I store “énial”

Someone can help me please ?

//

test_controller.rb :

class TestController < ActionController::Base

def index
end

def post
@var1 = params[:comment][:message]
@var2 = params[:comment][:message][0]
@var3 = params[:comment][:message].inspect

hash = { :name => params[:comment][:message] }
obj = Color.new( hash )
obj.save

end

end

index.rhtml :

<%= start_form_tag :action => ‘post’ %>

Message
<%= text_area "comment" , "message" %>

<%= submit_tag "Post" %> <%= end_form_tag %>

post.rhtml :

<%= @var1 %>

<%= @var2 %>

<%= @var3 %>


#2

On 17 Jan '06, at 12:04 PM, oo00oo wrote:

Hello, I have a problem with accentued characters return from a
textarea
index.rhml : If I put “énial” inside the textarea, then submit
to :action => post
post.rhml : wrote
énial
195
“\303\251nial”

Looks like a classic encoding mismatch: the browser is returning
UTF-8 and you’re expecting something different (probably WinLatin1,
aka CP-1252). Make sure your HTML has a tag specifying the
intended encoding.

params[:comment][:message][1] return => 195 ! ( 195 is not
“é” , http://www.asciitable.com/ )

195 may not be “é” in the particular encoding you’re used to, but
that doesn’t mean it isn’t in some other encoding. That
asciitable.com” site is rather naïve … “ascii” refers only to the
low 7 bits (0…127), and there is absolutely no agreed-on “extended
ascii” standard. There are dozens and dozens of different encodings
for (128…255), and there are encodings that encode some characters
using two or more bytes. UTF-8 is slowly becoming the lingua franca,
though.

This brings up the question in my mind of how to deal with UTF-8 in
Ruby. Last checked, there was no native support for different
character encodings or Unicode text. Has that been improved since
1.6? Or are there optional libraries we can use to work with Unicode?

–Jens


#3

Jens A. wrote:

This brings up the question in my mind of how to deal with UTF-8 in
Ruby. Last checked, there was no native support for different character
encodings or Unicode text. Has that been improved since 1.6? Or are
there optional libraries we can use to work with Unicode?

The canned response is KCODE=‘u’; require ‘jcode’; but that’s got a
whole bunch of holes in it. By strange coincidence, though, _why posted
this a couple of days ago:

http://redhanded.hobix.com/inspect/unicodeLibForRuby18.html


Alex


#4

2006/1/18, Alex Y. removed_email_address@domain.invalid:

http://redhanded.hobix.com/inspect/unicodeLibForRuby18.html

Optional library: http://rubyforge.org/projects/icu4r - still in
development :slight_smile:


#5

I have the same problem now, did u “win” it?

Thanks,
Mikhail