Problem with UTF-8 AJAX search


#1

Cheers,

I have an AJAX live search that works like this:

#view

<%= 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


#2

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).


#3

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/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 W.
http://blog.innerewut.de


#4

Perhaps try,

:with => “‘search=’ +encodeURIComponent(escape($F(‘search’)))”

Joshua Sierles


#5

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


#6

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