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>
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060118/ff31ea4a/attachment.html
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
2006/1/18, Alex Young <alex@blackkettle.org>:> 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 >Optional library: http://rubyforge.org/projects/icu4r - still in development :)