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

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.
jw (Guest)
on 2005-11-22 00: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 W.
http://blog.innerewut.de
listbox (Guest)
on 2005-11-22 16:05
(Received via mailing list)
On 21-nov-2005, at 23:30, Jonathan W. 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).
jw (Guest)
on 2005-11-22 18:34
(Received via mailing list)
>
> On 21-nov-2005, at 23:30, Jonathan W. wrote:
>
>> browser_filter
> What plugin is it? I cannot find it by googling.

http://dev.rubyonrails.org/svn/rails/plugins/brows...

>
> 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 W.
http://blog.innerewut.de
jsierles (Guest)
on 2005-11-23 12:30
(Received via mailing list)
Perhaps try,

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

Joshua Sierles
jw (Guest)
on 2005-11-23 15: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 W.
http://blog.innerewut.de
ilya (Guest)
on 2006-03-06 00: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 W.
> http://blog.innerewut.de
This topic is locked and can not be replied to.