Forum: Ruby on Rails field sets and unicode

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.
Mikhail S. (Guest)
on 2006-01-29 15:10
(Received via mailing list)
Hello gentlemen,

I've forced to such unicode problem:
I have:
<%= text_field_tag 'search', nil, :id => 'search', :size => 10 %>
<%= observe_field 'search',
  :url => {:controller => 'article', :action => 'search'},
  :with => "'terms=' + escape(value)",
  :update => 'search_results',
  :loading => "Element.show('search_spinner')",
  :loaded => "Element.hide('search_spinner')"
%>
in my article view, after sumbitting I get sequence like
u0444u0438u043bu043eu0441u043eu0444u0438u044f in controller
(params[:terms]).
How can I convert it into normal unicode? I am using UTF-8 as encoding.

Thanks,
Mikhail
Lugovoi N. (Guest)
on 2006-01-29 15:20
(Received via mailing list)
instead of escape()

>   :with => "'terms=' + escape(value)",

use encodeURIComponent(), which should work fine with UTF8:

encodeURIComponent('Ñ?илосоÑ?ия')  =>
%D1%84%D0%B8%D0%BB%D0%BE%D1%81%D0%BE%D1%84%D0%B8%D1%8F

2006/1/29, Mikhail S. <removed_email_address@domain.invalid>:
Mikhail S. (Guest)
on 2006-01-29 15:50
(Received via mailing list)
On Sun, 29 Jan 2006 15:17:12 +0200
Lugovoi N. <removed_email_address@domain.invalid> wrote:

> instead of escape()
>
> >   :with => "'terms=' + escape(value)",
>
> use encodeURIComponent(), which should work fine with UTF8

Thanks a lot, Nikolai!
This topic is locked and can not be replied to.