Forum: Ruby on Rails textarea problem with accentued chars

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
19403f509ca90e8ffe072214c6cba896?d=identicon&s=25 oo00oo (Guest)
on 2006-01-17 21:41
(Received via mailing list)
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' %>
  <p><label for="comment_message">Message</label><br/>
  <%= text_area "comment" , "message" %></p>
  <%= submit_tag "Post" %>
<%= end_form_tag %>

post.rhtml :
-----------

<p><%= @var1 %></p>
<p><%= @var2 %></p>
<p><%= @var3 %></p>
Edbd5f1c2f535b14165ae883fa7c3f37?d=identicon&s=25 Jens Alfke (Guest)
on 2006-01-18 02:00
(Received via mailing list)
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 <meta> 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
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-01-18 12:21
(Received via mailing list)
Jens Alfke 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
5c19f2d52879a1e10670c7334ba4c7e3?d=identicon&s=25 Lugovoi Nikolai (Guest)
on 2006-01-18 12:33
(Received via mailing list)
2006/1/18, Alex Young <alex@blackkettle.org>:
> http://redhanded.hobix.com/inspect/unicodeLibForRuby18.html
>

Optional library: http://rubyforge.org/projects/icu4r - still in
development :)
C0a32d16cf74103a6b8f31105cb04875?d=identicon&s=25 Mikhail Shevchuk (Guest)
on 2006-01-29 13:19
(Received via mailing list)
I have the same problem now, did u "win" it?

Thanks,
Mikhail
This topic is locked and can not be replied to.