Cheers,
I have an AJAX live search that works like this:
#view
<input type="text" id="search" name="search"
size="15" />
<%= observe_field(:search,
:frequency => 1.5,
:update => :results,
:url => { :controller =>
''uni'',
:action => :ajax_suche, },
:with =>
"''search='' +
escape($F(''search''))" )%>
#simplified controller
def ajax_suche
@query = params[:search]
@profs = Prof.search(@query)
render(:partial => ''ajax_suche'')
end
Further I have the browser_filter plugin installed.
Searching is working great, the problem is that when I enter Umlauts in the
search field they are not correctly transferred to the controller and
resulting view.
For example if I enter "ä" in the search field the request parameters
are
these:
Safari:
{"search"=>"\344", "_"=>""}
Firefox:
{"search"=>"��","_"=>""}
In the log I see searches for ''?'' that will not find results
with "ä" but
with "a".
Seems like a charset mess.
Any hints?
Regards,
Jonathan
--
Jonathan Weiss
http://blog.innerewut.de
On 21-nov-2005, at 23:30, Jonathan Weiss wrote:> browser_filterWhat plugin is it? I cannot find it by googling. You have to also verify that all of your components treat Unicode properly (from the database to HTML and back).
> > On 21-nov-2005, at 23:30, Jonathan Weiss wrote: > >> browser_filter > What plugin is it? I cannot find it by googling.http://dev.rubyonrails.org/svn/rails/plugins/browser_filters/> > You have to also verify that all of your components treat Unicode > properly (from the database to HTML and back).Unicode seems to work everywhere else. All my content is UTF-8 in MySQL and storing/retrieving works normally. Only the AJAX calls fail to treat UTF-8 correcly. Regards, Jonathan -- Jonathan Weiss http://blog.innerewut.de
Perhaps try,
:with => "''search=''
+encodeURIComponent(escape($F(''search'')))"
Joshua Sierles
On 11/22/05, Jonathan Weiss <jw-eM0Q5iXcOashFhg+JK9F0w@public.gmane.org>
wrote:> >
> > On 21-nov-2005, at 23:30, Jonathan Weiss wrote:
> >
> >> browser_filter
> > What plugin is it? I cannot find it by googling.
>
> http://dev.rubyonrails.org/svn/rails/plugins/browser_filters/
>
> >
> > You have to also verify that all of your components treat Unicode
> > properly (from the database to HTML and back).
>
> Unicode seems to work everywhere else. All my content is UTF-8 in MySQL and
> storing/retrieving works normally. Only the AJAX calls fail to treat UTF-8
> correcly.
>
> Regards,
> Jonathan
> --
> Jonathan Weiss
> http://blog.innerewut.de
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
> Perhaps try, > > :with => "''search='' +encodeURIComponent(escape($F(''search'')))" >Then if I enter ''ä'' into the search filed I get a search for ''%E4''. This will not find values with ''ä''.> Joshua SierlesThanks, Jonathan -- Jonathan Weiss http://blog.innerewut.de> > On 11/22/05, Jonathan Weiss <jw-eM0Q5iXcOashFhg+JK9F0w@public.gmane.org> wrote: >>> >>> On 21-nov-2005, at 23:30, Jonathan Weiss wrote: >>> >>>> browser_filter >>> What plugin is it? I cannot find it by googling. >> >> http://dev.rubyonrails.org/svn/rails/plugins/browser_filters/ >> >>> >>> You have to also verify that all of your components treat Unicode >>> properly (from the database to HTML and back). >> >> Unicode seems to work everywhere else. All my content is UTF-8 in MySQL and >> storing/retrieving works normally. Only the AJAX calls fail to treat UTF-8 >> correcly. >> >> Regards, >> Jonathan >> -- >> Jonathan Weiss >> http://blog.innerewut.de >> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
That''s odd... In which browser are you seeing the problem? Safari apparently has a problem with UTF-8 in AJAX: http://wiki.rubyonrails.com/rails/pages/HowToUseUnicodeStrings I''ve had the exact opposite problem, where AJAX uses UTF-8 but I need the search text as ISO-8859-1 (the solution to that problem is presented at: http://dema.ruby.com.br/articles/2005/07/22/playing-nice-with-ajax-and-iso-8859-1 ) best regards, torben> -----Original Message----- > From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of > Jonathan Weiss > Sent: 23. november 2005 14:36 > To: Ruby on Rails; Joshua Sierles > Subject: Re: [Rails] Problem with UTF-8 AJAX search > > > > Perhaps try, > > > > :with => "''search='' +encodeURIComponent(escape($F(''search'')))" > > > > Then if I enter ''ä'' into the search filed I get a search for > ''%E4''. This > will not find values with ''ä''. >
The trick for me seemed to use:
$KCODE = ''u''
require ''jcode''
And in the view DO NOT escape the string, so just
:with => "''search='' +
$F(''search'')"
in the view.
> best regards,
> torben
Regards,
Jonathan
--
Jonathan Weiss
http://blog.innerewut.de
>
>
>> -----Original Message-----
>> From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>>
[mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On
Behalf Of
>> Jonathan Weiss
>> Sent: 23. november 2005 14:36
>> To: Ruby on Rails; Joshua Sierles
>> Subject: Re: [Rails] Problem with UTF-8 AJAX search
>>
>>
>>> Perhaps try,
>>>
>>> :with => "''search=''
+encodeURIComponent(escape($F(''search'')))"
>>>
>>
>> Then if I enter ''ä'' into the search filed I get a
search for
>> ''%E4''. This
>> will not find values with ''ä''.
>>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
Then you have to decode it again in your controller? jw wrote:>> Perhaps try, >> >> :with => "''search='' +encodeURIComponent(escape($F(''search'')))" >> > > Then if I enter ''?'' into the search filed I get a search for ''%E4''. This > will not find values with ''?''. > >> Joshua Sierles > > Thanks, > Jonathan > -- > Jonathan Weiss > http://blog.innerewut.de-- Posted via http://www.ruby-forum.com/.