Forum: Ruby on Rails text_field_with_auto_complete and foreign characters

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.
64df72aa2735f96f380d3efe2d54afd1?d=identicon&s=25 Gernot Kogler (gkogler)
on 2006-04-13 10:06
I need a form where the user must enter a city name. I would like to use
an autocomplete_field for the city name, so I have the following code in
my view:

<%= text_field_with_auto_complete 'entry', 'city_name', :size => 40 %>

and in my controller I have the method:

def auto_complete_for_entry_city_name
  @cities = City.find(:all,
                      :conditions => [ 'LOWER(name) LIKE ?',
params[:entry][:city_name].downcase + '%'],
                      :order => 'name ASC',
                      :limit => 10)
  render :partial => 'cities'
end

This works fine, except when the city name has german umlauts like in
'Zürich'. It looks like I get the raw text from the city field in my
action method.
I then tried to use the observe_field feature like this:

<input type="text" id="city_name" name="city_name" size="40" />
<%= observe_field(:city_name,
                  :frequency => 0.5,
                  :update => :results,
                  :url => { :controller => 'entries',
                  :action => :find_city, },
                  :with => "'city_name=' + escape($F('city_name'))" )%>
<div class="autocomplete" id="results"></div>

This works fine with umlauts, too. The :with-option does the trick.
Unfortunately this is not what I need, I want an autocplete field. Is
there a way to escape the text from my input field using "the
text_field_with_auto_complete" ?
This topic is locked and can not be replied to.