Ruby Forum Ruby on Rails > Problem with UTF-8 AJAX search

Posted by jw (Guest)
on 21.11.2005 23:31
(Received via mailing list)
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
Posted by listbox (Guest)
on 22.11.2005 15:05
(Received via mailing list)
On 21-nov-2005, at 23:30, Jonathan Weiss wrote:

> browser_filter
What 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).
Posted by jw (Guest)
on 22.11.2005 17:34
(Received via mailing list)
> 
> 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
Posted by jsierles (Guest)
on 23.11.2005 11:30
(Received via mailing list)
Perhaps try,

:with => "'search=' +encodeURIComponent(escape($F('search')))"

Joshua Sierles
Posted by jw (Guest)
on 23.11.2005 14:37
(Received via mailing list)
> 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 by ilya (Guest)
on 05.03.2006 23:06
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